简体   繁体   中英

Object.defineProperty() works during testing (jpm run), but doesn't do anything when using the actual xpi

Well, here I am back again with another problem concerning parts of my addon.

I'm using an observer to modify values called through javascript.

var observerService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
observerService.addObserver(this, "document-element-inserted", false);

I'm doing this by observing 'document-element-inserted', which is

Sent immediately after the root element of a document has been created, but before executing any script on it. ( Source )

When called, my addon modifies several document/navigator/screen-values to reduce fingerprinting by overriding the navigator.X values:

Object.defineProperty(XPCNativeWrapper.unwrap(navigator), "plugins", {
    value: "",
});

In this case for example the plugin list, making it appear as if I don't have any plugins installed at all.

So far, this has been working fine in my development environment/jpm run. However, now that I've created an actual xpi, nothing happens. The code still gets called, I've used several console outputs in my jSTracking function, and all of them appeared in the browser console. However, the supposedly changed values are still the original ones.

There are only two errors which don't appear when using jpm run:

[Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIURI.hostPort]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: resource://gre/modules/PopupNotifications.jsm :: PopupNotifications_refreshPanel/< :: line 667" data: no] (unknown)

gets thrown twice during installation.

Use of nsIFile in content process is deprecated. Content.js:25:17

Use of nsIFile in content process is deprecated. NetUtil.jsm:335:12

Is the other one which appears from time to time, though never related to my scripts.

The thing that confuses me the most: Why does Object.defineProperty work with jpm run, but not with the xpi? What do I have to change to make it always work?

The whole project can be found at my Github repository.

The registering of the observer is in pp.js at line 452,

the observe-function is in lines 436-446

and the jsTracking function starts in line 193 and ends in line 433

The quoted plugin-example can be found in lines 399-403

I'd be grateful for any help, thanks!

Well, that was easier to 'fix' than I thought.

I was randomly browsing firefox topics, when I saw a mention of e10s/the multi-processor-functionality of firefox, and how not all addons are compatible.

Tried my addon with my standard firefox instead of the nightly build, and everything works as expected.

Therefore, my questions is answered, and I only have to worry about e10s compatability now.

Guess I'll look up bug reports over at bugzilla.mozilla.org to see if it's something I can easily fix or if it's maybe something they can add into the documentation on their end.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM