Unexpected XRay vision into content script objects
Categories
(WebExtensions :: Compatibility, defect)
Tracking
(Not tracked)
People
(Reporter: gcp, Unassigned)
References
Details
I hit a problem writing a WebExtension using external libraries. Googling while trying to figure it out, I found this, which explains the root issue: https://stackoverflow.com/questions/44671610/sandboxed-this-in-firefox-webextension-content-script
If a WebExtension content scripts adds objects onto the window object (via passing this into a function), they will disappear even within the content script itself.
Note that the answer saying its XRay vision must be wrong (at least as per our docs!): the object is added and observed inside a content script. No page objects are being accessed at all.
It's surprising, and as pointed out, a compat issue (not just with Chrome, but with other JS libraries too which assume they can retrieve thing set on this
via window
).
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts#Content_script_environment
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Sharing_objects_with_page_scripts
Comment 1•5 years ago
|
||
Hey :gcp,
based on your description from Comment 0 this sounds like a duplicate of Bug 1525400.
I'm going to close this new one as a duplicate of the existing bugzilla issue (because it has already details from the investigation :robwu and :bz already did), but feel free to re-open this issue if you have reasons to believe that this may be a different XRays-related issue than the one described in Bug 1525400.
Comment 2•5 years ago
|
||
Also, the more general reasons why this !== window
are in bug 1208775.
Comment 3•5 years ago
|
||
Unintentional.
Reporter | ||
Comment 4•5 years ago
•
|
||
Luca, should this be added to the docs?
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Chrome_incompatibilities
Given that it looks bug 1525400 and bug 1208775 have no easy fix.
Comment 5•5 years ago
|
||
based on your description from Comment 0 this sounds like a duplicate of Bug 1525400.
How so? Bug 1525400 is only an issue when bfcache restoration is involved. This bug doesn't mention anything about bfcache. What are the actual steps to reproduce the property disappearance in this bug?
Reporter | ||
Comment 6•5 years ago
|
||
See the StackOverflow code. I think that's really bug 1208775 because there's an implicit assumption this == window at global scope.
Comment 7•5 years ago
|
||
(In reply to Gian-Carlo Pascutto [:gcp] from comment #4)
Luca, should this be added to the docs?
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Chrome_incompatibilitiesGiven that it looks bug 1525400 and bug 1208775 have no easy fix.
Yeah, that's definitely a good point, I just filed https://github.com/mdn/sprints/issues/2656 to track the needed additions to the docs.
Description
•