Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CustomEvent documentation missing cloneInto information for web extension scripts #29232

Closed
marcustyphoon opened this issue Sep 21, 2023 · 5 comments · Fixed by #31168
Closed
Assignees
Labels
area: DOM/CSSOM Content:WebAPI Web API docs Content:WebExt WebExtensions docs effort: small This task is a small effort.

Comments

@marcustyphoon
Copy link
Contributor

marcustyphoon commented Sep 21, 2023

MDN URL

https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent

What specific section or headline is this issue about?

Section was removed in #9920.

What information was incorrect, unhelpful, or incomplete?

As per https://stackoverflow.com/a/46081249, CustomEvents with a non-string detail property will throw with "Permission denied to access property" in Firefox when they are used to communicate between the web extension content script isolated world and main world (this is the current state of the art in web extensions for cross-world communication, as I understand it). Calling cloneInto on the payload is required to avoid this.

There used to be a section describing this, but it was removed per #9920 (comment):

It was removed because the section talked about Firefox XUL/XPCOM extension code. We are trying to make MDN Web Docs only about Web technologies. XUL/XPCOM Firefox extensions don't exist anymore so it was removed for that reason. "privileged" referred to privileged code in an extension context.

XUL extensions may be gone, but WebExtensions certainly aren't, and this is the logical place where one who ran into this permission error would probably be looking for this information!

What did you expect to see?

An updated form of the removed passage, detailing this Firefox behavior and the cloneInto(/* whatever */, doc.defaultView) method required to use it, with the example changed to a web extension context and a note that Chromium does not have this behavior.

Link to the previous copy: https://github.com/mdn/content/blob/2279e5ae6c229c707a014a22aa1ec4635a0f981f/files/en-us/web/api/customevent/index.md

Do you have any supporting links, references, or citations?

No response

Do you have anything more you want to share?

Not sure if I should make an issue at https://github.com/w3c/webextensions/ describing this? It seems like a platform discrepancy that has gone largely uncommented-upon.

MDN metadata

Page report details
@marcustyphoon marcustyphoon added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Sep 21, 2023
@github-actions github-actions bot added the Content:WebAPI Web API docs label Sep 21, 2023
@wbamberg
Copy link
Collaborator

Do you think it would be OK to document this in the WebExtensions documentation, perhaps in the content scripts guide? This already has a section on communicating with the web page.

@marcustyphoon
Copy link
Contributor Author

Yeah, for sure! This is certainly WebExtension-specific, to my knowledge (there are no isolated worlds in normal web code, right?)

That section could definitely use a description of the CustomEvent communication method as well as the iframe-based method to pass a secure MessageChannel (w3c/webextensions#77 (comment)), as those seem to be the current best practices but they aren't really documented anywhere.

@marcustyphoon marcustyphoon changed the title CustomEvent documentation missing cloneInto information CustomEvent documentation missing cloneInto information for web extension scripts Sep 22, 2023
@wbamberg
Copy link
Collaborator

@rebloor , what do you think?

@rebloor
Copy link
Contributor

rebloor commented Sep 22, 2023

Seem reasonable to me - any comment @mdn/yari-content-mozilla-add-ons

@Rob--W
Copy link
Member

Rob--W commented Sep 23, 2023

Seem reasonable to me - any comment @mdn/yari-content-mozilla-add-ons

I'm in favor of documenting this more explicitly. Perhaps in the form of a small note stating the requirement when used in WebExtensions' content scripts to communicate with the web page, with a link to the extension documentation.

@Josh-Cena Josh-Cena added Content:WebExt WebExtensions docs area: DOM/CSSOM effort: small This task is a small effort. and removed needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. labels Sep 27, 2023
@rebloor rebloor self-assigned this Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: DOM/CSSOM Content:WebAPI Web API docs Content:WebExt WebExtensions docs effort: small This task is a small effort.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants