Closed Bug 1607242 Opened 5 years ago Closed 5 years ago

Unexpected XRay vision into content script objects

Categories

(WebExtensions :: Compatibility, defect)

x86_64
Linux
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 1208775

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

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.

Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → DUPLICATE
See Also: → 1525400

Also, the more general reasons why this !== window are in bug 1208775.

See Also: → 1208775

Unintentional.

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.

Flags: needinfo?(lgreco)

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?

See the StackOverflow code. I think that's really bug 1208775 because there's an implicit assumption this == window at global scope.

(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_incompatibilities

Given 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.

Flags: needinfo?(lgreco)
You need to log in before you can comment on or make changes to this bug.