Safari extensions: Pages restored from cache cannot receive messages!

Originator:marc.hoyois
Number:rdar://8507066 Date Originated:2010-10-03
Status:Duplicate/8108540 Resolved:
Product:Safari Product Version:5.0.5
Classification:Serious Bug Reproducible:Always
 
03-Oct-2010 02:30 PM Marc Hoyois:
Summary:
When Safari reloads a web pages entirely from cache, this page cannot receive any message sent by an extension's global page.

Steps to Reproduce:
1. Install the first attached extension. It has this global script:

function execute(event) {
    event.target.browserWindow.activeTab.page.dispatchMessage("name", "message");
}

safari.application.addEventListener("command", execute, false);

and this injected script:

safari.self.addEventListener("message", function(){alert("message received!");}, false);

2. Navigate to a lightweight page that Safari will save in its cache. For example, www.google.com.

3. Press the extension's toolbar button, and observe the 'message received' alert confirming that the page received the message sent by the global page.

4. Navigate away from the page (for example, click a link on the page).

5. Press the back button.

6. Press the toolbar button again.

Expected Results:
The page receives the message and alerts 'message received' as in step 3.

Actual Results:
Nothing happens!

Notes:
1. I was unable to find a workaround. The second attached extension is such an attempt. It has a different injected script:

function handlePageShowEvent(event) {
    alert("pageshow event fired. Registering listener to messages.")
    safari.self.addEventListener("message", function() {alert("message received!");}, false);
}

window.addEventListener("pageshow", handlePageShowEvent, true);

that registers the listener function to messages within a listener to the 'pageshow' event which is fired even when a page is restored from cache. However, this does not solve the problem.

2. I've also tried dispatching the message to all pages instead of using the browserWindow property of the toolbar button, but that doesn't solve the problem.

3. This affects every extension that uses messaging!

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!