(window instanceof Object) returns false in webextension content script
Categories
(WebExtensions :: General, defect)
Tracking
(Not tracked)
People
(Reporter: seva.luchianov, Unassigned)
References
(Depends on 1 open bug)
Details
User Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0
Steps to reproduce:
Type (window instanceof Object) in the console and evaluate.
Actual results:
returns false
Expected results:
should return true
Comment 1•6 years ago
|
||
I just tried that in the Jan 26 nightly build on Mac, but I can't reproduce the problem. Specific steps I used:
-
Run it with a clean profile.
-
Open the web console on the default page that gets opened when the browser starts (https://www.mozilla.org/en-US/privacy/firefox/) by hitting Cmd+Option+K.
-
Type "window instanceof Object" and hit enter.
The resulting value is "true".
Which exact build are you testing on? What exact steps are you using? Most importantly, which of the many consoles (web console, browser console, browser toolbox, browser content toolbox, etc) are you doing this in?
Reporter | ||
Comment 2•6 years ago
|
||
I am currently using Firefox Developer Edition 66.0b2 (64-bit) on Windows 7 Ultimate 64-bit
Signed in with my personal profile seva.luchianov@gmail.com
Here are the specific steps to reproduce:
I am using an unsigned addon that I am developing.
The content script run_at key in the manifest is "document_start"
In the content script, you can either breakpoint on anything right at the beginning of the script and eval in the console, or just put a console.log(window instanceof Object) in the script and it will log false.
In my code I have:
console.log(window instanceof Object);
document.addEventListener("DOMContentLoaded", function() {
console.log(window instanceof Object);
});
and both log false when the content script is loaded. However just letting the page load and trying to eval (window instanceof Object) in the console will indeed return true.
I have tried this on google.com and amazon.com and it behaves the exact same way.
I have also tried putting a breakpoint inside a script served up by the webpage itself rather than the extension and this issue was not reproducible there, so perhaps it appears to be localized to extensions?
I have also tested this in 64.0.2 (64-bit) and it is reproducible there.
This issue is not reproducible in Chrome Version 71.0.3578.98 (Official Build) (64-bit) while going through the same steps.
Reporter | ||
Comment 3•6 years ago
|
||
To further clarify, this is all being done in the developer tools web console that is accessed by hitting F12 on a page such as google.com.
Comment 4•6 years ago
|
||
OK, so the predicate is evaluated in the content script, not in the console. The console is just showing the result.
I expect this is because the content script is running in a separate global from the window (and in particular Object !== window.Object).
In Chrome, the "window" object is in the same global as the content script. This has some drawbacks (e.g. no direct access to the window's JS state, as I recall), but makes some other things simpler.
Reporter | ||
Comment 5•6 years ago
|
||
I see. I stumbled upon this bug while incorporating the VelocityJS 2.0.5b plugin into my code (https://github.com/julianshapiro/velocity). It's got around 2M/m downloads so this might affect many people who are upgrading the the Velocity V2 plugin.
Should I expect this to be fixed in any future release, or would you recommend pursuing an alternative? I will submit a bug report to the VelocityJS devs in the situation that this is still far from getting addressed.
Comment 6•6 years ago
|
||
I don't think there's an imminent change planned to this behavior, but I'm not an expert on the webextensions setup and the plans for it...
Reporter | ||
Comment 7•6 years ago
|
||
Alright. I've submitted a bug to the VelocityJS team, it's definitely much easier to fix on their end. Thanks for working with me on this one, as well as for the proposed window.Object reference. That should be simple for them to incorporate since it works in both the content script environment as well as the standard window environment.
Updated•6 years ago
|
Description
•