I have the following simplified code:
main.js:
var data = require("sdk/self").data;
var tabs = require("sdk/tabs");
tabs.on('ready', function(tab) {
console.log("start");
let worker = tab.attach({
contentScriptFile: [
data.url("jquery.min.js"),
data.url("test.js")
],
});
worker.port.emit("start", data.load("popups/start.html"));
console.log("end");
});
test.js:
console.log("test.js");
self.port.on("start", function (content) {
console.log("I get the message");
$('body').append(content);
});
The problem:
This works just fine and everything is ok in most cases. In only one web site and specifically in well known github.com, it produces the following error:
console.log: test: start
console.log: test: end
console.error:
Message: Error: call to Function() blocked by CSP
console.error:
Message: TypeError: this.sandbox is undefined
Stack:
receive#resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/content/worker-child.js:75:7
emitOnObject#resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/event/core.js:112:9
emit#resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/event/core.js:89:38
processMessageReceived#resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/commonjs/sdk/remote/child.js:54:38
Note 1: The problem is with the exchange of the message start. But why it is working everywhere else except the github.com/*?
Note 2: I'm using cfx, with jpm it works fine. Is any way to fix that or I have to update my extension to run with jpm?
cfx is probably including an old version of the SDK while jpm runs with the browser's built-in version. Try running with --strip-sdk.
That said, cfx is deprecated, you should use jpm.
Github uses CSP directives to block unsafe script execution including eval and new Function(), many other sites don't.
Newer SDK versions initialize the addon script sandbox differently so it is not affected by CSPs.
Related
I am new to react-native and working on a project in react-native. I integrated socket using following code.
this.socket = socketIO.connect(global.socketUrl, {
jsonp: false,
reconnection: true,
reconnectionDelay: 1000,
reconnectionDelayMax: 5000,
reconnectionAttempts: Infinity
});
Further I created instance of SocketManager class in my component using below code.
Obj= new SocketManger()
This code is working fine in debug build, but we are getting the following error
TypeError: Cannot read property 'initialize' of undefined\n at new Socket
TIA
We also followed answer mention at Here but not getting any accurate result. with this code we are getting below error.
After doing a lot of research i found my mistake. global variables doesn't work in IOS (Release Build). The issue was because of this global variable.
So i changed my code to
this.socket = socketIO.connect('url', {
jsonp: false,
reconnection: true,
reconnectionDelay: 1000,
reconnectionDelayMax: 5000,
reconnectionAttempts: Infinity
});
Now its working perfectly both in Android as well as IOS
I'm getting the error ('this.fs.stat is not a function') on line 2256 of lokijs.js. Environment is Electron with Angular 5.x and LokiJS v1.5.3.
fs is set up on line 2244 of lokijs.js (this.fs = require('fs');) but when I examine this.fs in the browser tools immediately after that line executes, it is just an empty object.
I've been beating my head against LokiJS all afternoon and have managed to get this far, but have no idea where to go from here. fs has been in node since forever, so I don't think it's an issue with a node version.
I'm aware of the issues with require and webpack, but since this is happening in LokiJS, I'm not sure whether this is related and if so what the proper fix would be.
Any ideas/suggestions?
Thanks.
Update #1
Code:
import * as Loki from 'lokijs';
import { LokiFsAdapter } from 'lokijs';
this.adapter = new LokiFsAdapter();
this.db = new Loki('my.db', {
env: 'NODEJS',
autoload: true,
autosave: true,
verbose: true,
autoloadCallback: this.initCollections
});
This gets me the error I mentioned above. If I switch the first line to import { Loki } from 'lokijs'; I get this error instead: Uncaught (in promise): TypeError: lokijs_1.Loki is not a constructor
I'm trying to use ember-cli-mirage in my tests but running into problems. I'm using ember and ember-data 2.1.0 so that may have something to do with this.
I'm able to use mirage in development just fine. I've defined factories, routes, scenarios, etc with no problem.
The problem is when i attempt to create models in tests. The test below errors out:
import Ember from 'ember';
import { module, test } from 'qunit';
import startApp from 'frontend/tests/helpers/start-app';
let application;
module('Acceptance | Customer', {
beforeEach() {
application = startApp();
},
afterEach() {
Ember.run(application, 'destroy');
}
});
test('viewing customers', function(assert) {
server.createList('customer', 2);
visit('/admin/customers');
andThen(() => assert.equal(find('#customers-table tbody tr').length, 2));
});
This results in:
not ok 1 PhantomJS 1.9 - Acceptance | Customer: viewing customers
---
actual: >
null
message: >
Died on test #1 at http://localhost:7357/assets/test-support.js:3124
at http://localhost:7357/assets/frontend.js:2434
at http://localhost:7357/assets/vendor.js:150
at tryFinally (http://localhost:7357/assets/vendor.js:30)
at http://localhost:7357/assets/vendor.js:156
at http://localhost:7357/assets/test-loader.js:29
at http://localhost:7357/assets/test-loader.js:21
at http://localhost:7357/assets/test-loader.js:40
at http://localhost:7357/assets/test-support.js:6846: 'undefined' is not a function (evaluating 'newCollection[method].bind(newCollection)')
Log: |
...
Should I be bootstrapping mirage somewhere?
This is actually caused by Phantom 1.9 not having bind (you can see in the error message, undefined refers to bind).
If you view the other notes section of the Installation docs you'll see you can get around this by installing ember-cli-es5-shim (or upgrading to PhantomJS 2.0).
When running my app in development it works fine. but when deployed, it throws this error :
Error: [$injector:unpr] Unknown provider: e
The url to the app : http://shimizu.leafycode.com/panel/signin
The js files : https://gist.github.com/THPubs/3a9e088ad3410e18030c
I followed other stack-overflow answers and fixed my app accordingly but still the problem is there! Please help.
Your code is being minified and I can see at least one place in app.js where you are not using the array notation when calling .config and .run
So in your app.js update the line
.config(function($mdThemingProvider) {
to
.config(['$mdThemingProvider', function($mdThemingProvider) {
// ... Your code ...
}])
and the line
.run(function($rootScope, $templateCache) {
to
.run(['$rootScope', '$templateCache', function($rootScope, $templateCache) {
// .. Your code ...
}])
Double check other places in your code that you are injecting services.
I have the following code in my bootstrapped Thunderbird add-on main.js file:
exports.main = function() {
console.log("abc");
};
When I run this code in FireFox in Add-on Builder, I get this message displayed in FireFox Error Console:
info: vladp: abc
However, when I run my extension in Thunderbird nothing is displayed. I have set up the development enviroment as described here: https://developer.mozilla.org/en-US/docs/Setting_up_extension_development_environment
How do I make it work in Thunderbird Error Console? Or is there any other way to log some debug information, apart from "dump()"?
UPDATE 1
As suggested by speedball2001, I've changed my code to:
exports.main = function() {
var Application = Components.classes["#mozilla.org/steel/application;1"].getService(Components.interfaces.steelIApplication);
Application.console.log('Bam!');
};
However, when I run Thunderbird, I get the following error in error console:
Timestamp: 2013.05.22. 16:39:07
Error: myfirstext: An exception occurred.
ReferenceError: Components is not defined
resource://jid0-7yp22cmsooypei7nicamg3n0ha0-at-jetpack/myfirstext/lib/main.js 57
How do I fix it?
Thunderbird provides an Application interface that, among other things, helps with logging:
var {Cc, Ci} = require("chrome");
var Application = Cc["#mozilla.org/steel/application;1"]
.getService(Ci.steelIApplication);
Application.console.log('Bam!');