chrome is undefined in microsoft edge extension - google-chrome-extension

Good day, I've written an extension which I would like run on every platform/browser. It works fine with chrome and firefox but just got error with ie-edge on windows 10. It keeps throwing chrome is not defined. Is there a way to make it define as I've been using through out my extension.
Thanks
export default {
browserAction: {
onClicked: chrome.browserAction !== undefined ? chrome.browserAction.onClicked : undefined,
setBadgeText: chrome.browserAction !== undefined ? chrome.browserAction.setBadgeText : undefined,
setTitle: chrome.browserAction !== undefined ? chrome.browserAction.setTitle : undefined,
setIcon: chrome.browserAction !== undefined ? chrome.browserAction.setIcon : undefined,
},
extension: {
getURL: chrome.extension !== undefined ? chrome.extension.getURL : undefined,
},
runtime: {
onMessage: chrome.runtime.onMessage || browser.runtime.onMessage,
reload: chrome.runtime.reload,
sendMessage: chrome.runtime.sendMessage,
},
tabs: {
create: chrome.tabs !== undefined ? chrome.tabs.create : undefined,
executeScript: chrome.tabs !== undefined ? chrome.tabs.executeScript : undefined,
get: chrome.tabs !== undefined ? chrome.tabs.get : undefined,
onActivated: chrome.tabs !== undefined ? chrome.tabs.onActivated : undefined,
onUpdated: chrome.tabs !== undefined ? chrome.tabs.onUpdated : undefined,
query: chrome.tabs !== undefined ? chrome.tabs.query : undefined,
remove: chrome.tabs !== undefined ? chrome.tabs.remove : undefined,
sendMessage: chrome.tabs !== undefined ? chrome.tabs.sendMessage : undefined,
},
webRequest: {
onBeforeRedirect: chrome.tabs !== undefined ? chrome.webRequest.onBeforeRedirect : undefined,
},
};

The error could be fixed by simply installing Microsoft Edge Extension Toolkit. Here is how you can load the extension into toolkit .

Related

How to parse a json file with nodejs

I got a little problem with the nodejs fetch module and more particularly with the JSON parse. When I want to parse the stock variable, he tells me that the size is equal to 0 ? But my file is not empty and the path is good.
The code is really simple but I don't know why this error append and I spend too much time on this.
Someone know why I get this error and how I can resolve it ?
here the code of my js file :
const fetch = require('node-fetch');
const keyword='test';
const url='http://localhost:8888/test.json';
fetch(url).then((stock) => {
console.log(stock);
const jsonFile = JSON.parse(stock);
const newCategory = jsonFile[test];
console.log(newCategory);
}).catch((e)=>{console.log(e)});
And the error in my terminal with the first console.log() :
Response {
size: 0,
timeout: 0,
[Symbol(Body internals)]:
{ body:
PassThrough {
_readableState: [ReadableState],
readable: true,
_events: [Object],
_eventsCount: 2,
_maxListeners: undefined,
_writableState: [WritableState],
writable: false,
allowHalfOpen: true,
_transformState: [Object] },
disturbed: false,
error: null },
[Symbol(Response internals)]:
{ url: 'http://localhost:8888/test.json',
status: 200,
statusText: 'OK',
headers: Headers { [Symbol(map)]: [Object] },
counter: 0 } }
SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse (<anonymous>)
at fetch.then (/Users/me/Desktop/test_json/index.js:11:30)
at process._tickCallback (internal/process/next_tick.js:68:7)
The fetch api returns a Body object
you can call Body.json()
Using async/await:
const body = await fetch(url);
const json = await body.json();
console.log(json);
Using promises:
fetch(url).then((stock) => {
return stock.json()
}).then(json => {
console.log(json);
});
JSON.parse:
fetch(url).then((stock) => {
return stock.text()
}).then(text => {
console.log(JSON.parse(text));
});
You need to pass the body in json parse like bellow,
JSON.parse(stock.text())
Or you can directly use json data without parsing just using stock.json() function

Sourcemaps in puppeteer?

I'm puppeteering (could this be a verb?) an app built with webpack and on page.on('error') I get errors like this:
TypeError: __WEBPACK_IMPORTED_MODULE_0_babel_runtime_core_js_promise___default.a.map is not a function
at _default.<anonymous> (....../app.js:23858:89)
at Generator.next (<anonymous>)
at step (....../app.js:35041:30)
at ....../app.js:35052:13
Is there a way, and if so how could I get these errors correctly sourcemapped?
(I know for sure I'm generating the sourcemaps)
I did it in the following way... A bit delayed but someone might find it useful.
Once you have navigated to the page throwing the error you inject this lib: https://github.com/novocaine/sourcemapped-stacktrace
await page.addScriptTag({
url: 'https://cdn.jsdelivr.net/npm/sourcemapped-stacktrace#1.1.8/dist/sourcemapped-stacktrace.js',
});
Then you listen for the error events:
page.on('pageerror', logStackTrace);
page.on('error', logStackTrace);
In the logStackTrace function you extract the sourcemapped stacktrace as follows and log it:
const logStackTrace = async (error) => {
page.evaluate(stack => new Promise(resolve =>
window.sourceMappedStackTrace.mapStackTrace(stack, (newStack) => {
resolve(newStack);
})
), typeof error.stack === 'string' ? error.stack : error.stack.join('\n'))
.then((result) => {
console.log('ERROR:', error.message, result[0]);
});
};
It only correctly maps the first line of the stack for me though. Still infinitely more useful.
If you use one of the eval variants for your webpack devtool then Puppeteer should pick it up:
// webpack.config.js
module.exports = {
// ...
mode: 'development',
devtool: 'eval-source-map',
};

hapijs OnRequest server extension doesn't access the server plugin

i18n for internationalization purpose.
When user send the language code on url i will change the language of i18n like this http://localhost:8080/signup?language=en
For that i am using the server extension OnRequest. So that on it will global for each route,
but the problem occurs is when i access the i18n in OnRequest its shows undefined error
But in the route handler it shows all the properties of the hapi-i18n
Here is my code and output
server.ext('onRequest', function(request, response){
console.log("pre handler");
console.log(request.i18n);
return response.continue();
});
Output:
Undefined
But in the handler
{
method : 'POST',
path : "/signup",
config : {
tags : ['api'],
description : 'Customer signup',
},
handler: function(request, response){
console.log(request.i18n);
}
}
Output:
{ __: [Function],
__n: [Function],
getLocale: [Function],
setLocale: [Function],
getCatalog: [Function],
locale: 'en'
}
You need to use the onPostAuth extension point as the module you are using manipulates request object in the onPreAuth extension point during request object lifecycle.

Make an api with node.js

I have tried build an api using node.js (+express).
The Firefox display it but when I try to load it with loadJSON from p5.js it shows weird error.
Here is node.js code (based on this: modulus: create api with node.js ):
express = require("express");
app = express();
app.listen(4000);
var quotes = [
{ author : 'Audrey Hepburn', text : "Nothing is impossible, the word itself says 'I'm possible'!"},
{ author : 'Walt Disney', text : "You may not realize it when it happens, but a kick in the teeth may be the best thing in the world for you"},
{ author : 'Unknown', text : "Even the greatest was once a beginner. Don't be afraid to take that first step."},
{ author : 'Neale Donald Walsch', text : "You are afraid to die, and you're afraid to live. What a way to exist."}
];
app.get('/', function(req, res){
res.json(quotes);
})
p5.js:
function setup() {
loadJSON("http://localhost:4000/", getJson, error1);
}
function getJson(data) {
console.log("json get");
console.log(data)
}
function error1(err) {
console.log("Error: ");
console.log(err);
}
Error:
"Error: "
{
"statusText": "",
"status": 0,
"responseURL": "",
"response": "",
"responseType": "",
"responseXML": null,
"responseText": "",
"upload": {
"ontimeout": null,
"onprogress": null,
"onloadstart": null,
"onloadend": null,
"onload": null,
"onerror": null,
"onabort": null
},
"withCredentials": false,
"readyState": 4,
"timeout": 0,
"ontimeout": null,
"onprogress": null,
"onloadstart": null,
"onloadend": null,
"onload": null,
"onerror": null,
"onabort": null
}
I have tried using 'jsonp' but it shows this:
5209: Uncaught TypeError: Cannot read property 'responseText' of undefined
I have node.js v4.2.2 and p5.js v0.5.4 October 01, 2016.
I seems likely that you have a cross origin issue when accessing the API from a browser.
What errors do you see in the browser console? If so, you can fix it by either allowing cross origin access on your server or by loading your web page from the same web server (which would make your api the same origin).

node:js:Uncaught TypeError: Cannot read property 'prototype' of undefined

I am using fs-extra for moving my folders but I am getting this error
Uncaught TypeError: Cannot read property 'prototype' of undefined
My code like below
var fse = require('fs-extra');
fse.move('/meteor/crm/uploads', '/meteor/crm/uploads/tmp', function (err) {
if (err) return console.error(err)
console.log("success!")
})
What can be the reason?
try adding target: 'node', to your webpack config

Resources