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

Add documentation of component.utils exportFunction and cloneInto #30877

Merged
merged 17 commits into from
Sep 20, 2024

Conversation

rebloor
Copy link
Contributor

@rebloor rebloor commented Dec 8, 2023

Description

WIP to add component.utils exportFunction and cloneInto.

Todo:

Motivation

These functions are references in Sharing objects with page scripts but not documented on MDN.

Related issues and pull requests

Fixes #29771
BCD mdn/browser-compat-data#22767

@rebloor rebloor added the Content:WebExt WebExtensions docs label Dec 8, 2023
@rebloor rebloor requested a review from rpl December 8, 2023 18:06
@rebloor rebloor self-assigned this Dec 8, 2023
Copy link
Contributor

github-actions bot commented Dec 8, 2023

Preview URLs

Flaws (9)

URL: /en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts
Title: Content scripts
Flaw count: 1

  • broken_links:
    • Can't resolve /en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts/cloneinto

URL: /en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts/cloneInto
Title: cloneInto()
Flaw count: 5

  • broken_links:
    • Can't resolve /en-US/docs/Mozilla/Add-ons/WebExtensions/API/Content_scripts/exportFunction
    • Anchor not lowercase
    • Anchor not lowercase
    • Can't resolve /en-US/docs/Mozilla/Add-ons/WebExtensions/API/components/utils/exportFunction
  • bad_bcd_queries:
    • No BCD data for query: webextensions.api.contentScriptGlobalScope.cloneInto

URL: /en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts/exportFunction
Title: exportFunction()
Flaw count: 2

  • broken_links:
    • Anchor not lowercase
  • bad_bcd_queries:
    • No BCD data for query: webextensions.api.contentScriptGlobalScope.exportFunction

URL: /en-US/docs/Mozilla/Add-ons/WebExtensions/Sharing_objects_with_page_scripts
Title: Share objects with page scripts
Flaw count: 1

  • broken_links:
    • Can't resolve /en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts/cloneinto
External URLs (3)

URL: /en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts/cloneInto
Title: cloneInto()


URL: /en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts/exportFunction
Title: exportFunction()

(comment last updated: 2024-09-20 16:58:46)

@rebloor rebloor marked this pull request as ready for review December 12, 2023 01:45
@rebloor rebloor requested a review from a team as a code owner December 12, 2023 01:45
Copy link
Member

@Rob--W Rob--W left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Components.utils API is an internal implementation detail of Firefox. Many years ago legacy Firefox add-ons had access to it, but WebExtensions don't. Their content scripts only have access to cloneInto/exportFunction, which exposes the same functionality.

There may be old links on the web pointing to these methods; if that is the concern I'd rather want redirects to the WebExtension-specific documentation.

If you need a place to host the method descriptions, I recommend to put them under Content_scripts/.


{{Compat}}

> **Note:** This API is based on Chromium's [`chrome.devtools`](https://developer.chrome.com/docs/extensions/mv2/devtools/) API.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a mistake? This API is Firefox-only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rob--W Indeed - I'll remove it.

@rebloor
Copy link
Contributor Author

rebloor commented Dec 27, 2023

@Rob--W I'm a little unclear about your feedback.

The Components.utils API is an internal implementation detail of Firefox. Many years ago legacy Firefox add-ons had access to it, but WebExtensions don't. Their content scripts only have access to cloneInto/exportFunction, which exposes the same functionality.

Just background?

There may be old links on the web pointing to these methods; if that is the concern I'd rather want redirects to the WebExtension-specific documentation.

The concern was, as per the issue: there is no documentation for exportFunction() and cloneInto() on MDN, however they are mentioned on Share objects with page scripts but only with examples but not syntax documentation or links to that documentation for the functions.

If you need a place to host the method descriptions, I recommend to put them under Content_scripts/.

Do you mean:

  • Add-ons/WebExtensions/Content_scripts/components/utils/exportFunction
  • Add-ons/WebExtensions/Content_scripts/components/utils/cloneInto

Or could we simplify to :

  • Add-ons/WebExtensions/Content_scripts/exportFunction
  • Add-ons/WebExtensions/Content_scripts/cloneInto

If we aren't following the usual API pattern and as neither the component nor utils page provides much information.

Or under the Share objects with page scripts?

@rebloor rebloor requested a review from Rob--W December 27, 2023 23:39
@Rob--W
Copy link
Member

Rob--W commented Dec 28, 2023

@Rob--W I'm a little unclear about your feedback.

The Components.utils API is an internal implementation detail of Firefox. Many years ago legacy Firefox add-ons had access to it, but WebExtensions don't. Their content scripts only have access to cloneInto/exportFunction, which exposes the same functionality.

Just background?

No, not just background information. I am asserting that it does not make sense to add the articles for Components and Components.utils, because there is no way for extensions to use these today. The MDN articles for these existed in the past for the reasons I mentioned before, but were removed when Firefox-only (internal) APIs were removed from MDN. In case you are curious, this is how the documentation of Components.utils.exportFunction looked like in the past:

The concern was, as per the issue: there is no documentation for exportFunction() and cloneInto() on MDN, however they are mentioned on Share objects with page scripts but only with examples but not syntax documentation or links to that documentation for the functions.

If you need a place to host the method descriptions, I recommend to put them under Content_scripts/.

Do you mean:

* Add-ons/WebExtensions/Content_scripts/components/utils/exportFunction

* Add-ons/WebExtensions/Content_scripts/components/utils/cloneInto

No.

Or could we simplify to :

* Add-ons/WebExtensions/Content_scripts/exportFunction

* Add-ons/WebExtensions/Content_scripts/cloneInto

Yes. That is what I meant.

@rebloor
Copy link
Contributor Author

rebloor commented Dec 28, 2023

Thanks @Rob--W I've rearranged the content and added cross-references. Do you think we need to add the to functions to the navigation e.g.:

  • Concepts
    • JavaScript APIs
    • Content scripts
    • exportFunction()
    • cloneInto()

(I'm not even sure it's possible, we don't do this with any of the other narrative content.)

If we're not considering these as part of the supported web extension API set, do you think we need browser compatibility data?

Copy link
Member

@Rob--W Rob--W left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is partial feedback, please apply the general issues broadly to the whole PR and then request another review.


## Examples

This add-on script creates an object, clones it into the content window and makes it a property of the content window global:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you replace all references of "add-on script" with "content script"? The original Components.utils.cloneInto method and its family of functions was documented in a general way because privileged code in add-ons, in general, could use this API anywhere. But in WebExtensions, only content scripts (and userScripts) can use it.

@github-actions github-actions bot added the size/m [PR only] 51-500 LoC changed label Apr 4, 2024
@github-actions github-actions bot added the merge conflicts 🚧 [PR only] label Jul 26, 2024
Copy link
Contributor

This pull request has merge conflicts that must be resolved before it can be merged.

@github-actions github-actions bot removed the merge conflicts 🚧 [PR only] label Jul 26, 2024
Copy link
Member

@Rob--W Rob--W left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks technically accurate. Could you address the nits and merge it?

An Xray for an object refers to the original. Any changes to the argument made in the exported function affect the original object passed in. For example:

```js
// ad// privileged scope: for example, a content script
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is ad// doing here and in other places below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea, some search/replace error, but a bit of head-scratcher.

@rebloor rebloor merged commit 9f953f3 into mdn:main Sep 20, 2024
8 checks passed
@rebloor rebloor deleted the components.utils branch September 20, 2024 17:09
fiji-flo pushed a commit that referenced this pull request Oct 2, 2024
…0877)

* Add documentation of component.utils exportFunction and cloneInto

* Resolved broken links, various edits

* various edits

* Various edits

* Remove incorrect "based on" note

* move exportFunction and cloneInto under Content_scripts

* Cross-reference and slug corrections

* Apply suggestions from review

Co-authored-by: Rob Wu <[email protected]>

* Further updates from feedback

* casing fix

* Apply suggestions from review

Co-authored-by: Rob Wu <[email protected]>

* Remove spurious ad//

---------

Co-authored-by: Rob Wu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:WebExt WebExtensions docs size/m [PR only] 51-500 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

exportFunction() and cloneInto() Syntax Documentation missing
2 participants