Closed Bug 734201 Opened 12 years ago Closed 12 years ago

Tutorial for interaction with page scripts through page mod.

Categories

(Add-on SDK Graveyard :: Documentation, defect, P1)

x86
macOS
defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: irakli, Assigned: wbamberg)

Details

Attachments

(1 file)

Lot's of people raise this question and we usually propose to use undocumented and unsupported `unsafeWindow` of the page mode. We should not do that as we might even remove it in a future. Instead we should write tutorial about how to do that in a correct way which would be more or less what is done here:

https://developer.mozilla.org/en/Code_snippets/Interaction_between_privileged_and_non-privileged_pages
Summary: Tutorial for interaction with page scripts through page mode. → Tutorial for interaction with page scripts through page mod.
Will. I'd give this a P1.5 were there such a thing ;)
Assignee: nobody → wbamberg
Priority: -- → P1
I'm a bit confused about this.

If you mean, a tutorial explaining interaction between a content script and a page script, my understanding was that it's done using window.postMessage: https://developer.mozilla.org/en/DOM/window.postMessage, and this is already documented in the SDK here: https://addons.mozilla.org/en-US/developers/docs/sdk/1.6/dev-guide/guides/content-scripts/access.html - although that should be expanded and perhaps packaged as a tutorial.

Is the technique of using DOM custom events an additional technique that should be added there? Is it preferable to using window.postMessage? Or is it complementary?
(In reply to Will Bamberg [:wbamberg] from comment #2)
> I'm a bit confused about this.
> 
> If you mean, a tutorial explaining interaction between a content script and
> a page script, my understanding was that it's done using window.postMessage:
> https://developer.mozilla.org/en/DOM/window.postMessage, and this is already
> documented in the SDK here:
> https://addons.mozilla.org/en-US/developers/docs/sdk/1.6/dev-guide/guides/
> content-scripts/access.html - 

I have probably missed this one. 

> although that should be expanded and perhaps
> packaged as a tutorial.
> 

Yeah I think tutorial would be a great addition, explaining how one could use thin instead of `unsafeWindow`.

> Is the technique of using DOM custom events an additional technique that
> should be added there? Is it preferable to using window.postMessage? Or is
> it complementary?

I don't think it's much different from `postMessage`. It's just if document uses `postMessage` for something else add-on will be notified and there is this complication of using document.defaultView...

With custom events as described in the link below, you wont have this issues but it's
bit verbose:
https://developer.mozilla.org/en/Code_snippets/Interaction_between_privileged_and_non-privileged_pages
In the end I kept this inside the "content scripts guide" rather than adding a new tutorial. I feel it's better to have all this stuff together. But I split the old "access" page into 2 new pages, "Accessing the DOM" and "Communicating With Other Scripts" which should hopefully improve discoverability.
Attachment #641933 - Flags: review?(rFobic)
Comment on attachment 641933 [details]
pointer to pull request

Please see improvement suggestions in the pull request
Attachment #641933 - Flags: review?(rFobic) → review+
Commit pushed to master at https://github.com/mozilla/addon-sdk

https://github.com/mozilla/addon-sdk/commit/8c602be7ce2ae1a73eaa7f7534bb8e78e17c5bb0
Merge pull request #489 from wbamberg/734201

Fix bug 734201 - Tutorial for interaction with page scripts through page mod.
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Commit pushed to stabilization at https://github.com/mozilla/addon-sdk

https://github.com/mozilla/addon-sdk/commit/c8d9ad5525451d1363cd7cbf0809776a4e73ef32
Merge pull request #489 from wbamberg/734201

Fix bug 734201 - Tutorial for interaction with page scripts through page mod. (cherry picked from commit 8c602be7ce2ae1a73eaa7f7534bb8e78e17c5bb0)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: