Closed Bug 1050327 Opened 10 years ago Closed 7 years ago

worker pageshow event fires before the worker's port can send messages

Categories

(Add-on SDK Graveyard :: General, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED INCOMPLETE

People

(Reporter: baseten_design, Unassigned)

References

Details

Attachments

(1 file)

Attached file firefox.zip
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36 Steps to reproduce: - add a listener to the 'pageshow' event of the worker passed into the 'onAttach' callback of a PageMod, store each worker in an array to keep track of multiple pages - in the pageshow listener try to send a message to the worker's content script via port.emit - when testing the add-on load a page, navigate to another page and then click back - the first page loads from the cache, the pageshow event fires and the port.emit is called on the worker A zip containing full source code for an add on is attached. Remove the setTimeout on line 71 of main.js to see the error. Actual results: Triggers the error: 'The page is currently hidden and can no longer be used until it is visible again.' Expected results: The page show event should not have fired until the worker is able to send a message to the content script. If a setTimeout of 0 is used before an attempt to send this message, it fires correctly.
Irakli: i misunderstood this part during our triage meeting, i thought he was using `pageshow` events on the tab object.. (In reply to Alex Prokop from comment #0) > - add a listener to the 'pageshow' event of the worker passed into the > 'onAttach' callback of a PageMod, store each worker in an array to keep > track of multiple pages you are using an internal event of our implementation, which i don't even think is documented anywhere. the problem here is that that same event is used by the SDK code to "unfreeze" the page worker after the tab navigates back to a page from BFCache. we can't really guarantee SDK code will run before your code, so that's why this happens. the solution for you is to listen for the `pageshow` event in your content script, and send a message back to your addon code from that event listener. that will guarantee your code will be able to interact with a content worker at that point.
Flags: needinfo?(tomica+amo)
Flags: needinfo?(rFobic)
Documented or not pageshow / pagehide events have being added as they were necessary to handle certain use cases by add-on authors. That is in fact why events are emitted on worker instances: https://github.com/mozilla/addon-sdk/blob/master/lib/sdk/content/worker.js#L216-L228 SDK does not really depends on events dispatched on `worker` instances. I also suspect that this bug is caused by the fact that `model.frozen` is mutated after event is emitted. I believe in the past `emit` was async which is why it was mutation of `model.frozen` after worked. zombie would you be willing to take this bug ?
Flags: needinfo?(rFobic)
Priority: -- → P1
subtle event timings/orderings like this are going out the window with e10s and my fix in bug 1058698, so i can take this after that lands.. (though i don't necessarily agree this is P1)
Depends on: 1058698
Priority: P1 → --
Status: UNCONFIRMED → RESOLVED
Closed: 7 years ago
Resolution: --- → INCOMPLETE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: