w3c / webextensions

Charter and administrivia for the WebExtensions Community Group (WECG)
Other
605 stars 56 forks source link

Inconsistent Navigation History Behavior Across Browsers with Resource URLs Using `tabs.update()` #677

Closed mshibanami closed 2 months ago

mshibanami commented 3 months ago

The following code handles navigation history differently across Firefox, Chrome, and Safari, and I'd like to know the expected behavior or whether we have a chance to define the expectation:

chrome.tabs.update(
    tabId,
    { chrome.runtime.getURL("test.html") });

When running the above code:

Which one is expected? Or do we have a chance to standardize the behavior across browsers, especially regarding the navigation history?

Demo

This is the demo of creating a new tab with example.com and then opening test.html bundled into the extension. https://github.com/user-attachments/assets/bbb3a5ce-768f-4fb6-8f5a-810cba25517f https://github.com/user-attachments/assets/a9e50a7d-19fd-4cde-85db-13d296c1368e https://github.com/user-attachments/assets/4e194c1a-051e-4898-af34-1fb7f4202200
And this is the code I actually used in the above demo. ```js // Safari and Firefox chrome.tabs.create({ url: "https://example.com" }) .then(tab => { const tabId = tab.id; setTimeout(() => { let url = chrome.runtime.getURL("test.html"); chrome.tabs.update( tabId, { url }); }, 1000); }); // Chrome chrome.tabs.create( { url: "https://example.com" }, (tab) => { setTimeout(() => { let url = chrome.runtime.getURL("test.html"); chrome.tabs.update( tab.id, { url }); }, 3000); }); ```

A use case

My Safari extension has a feature of redirecting to another app. Specifically, when the user tries to open a web page, the extension first navigates to a loading page bundled into the extension, and then the extension opens another app by running a native CLI command. However, opening the loading page causes Safari to delete the navigation history, preventing the user from returning to the previous web pages. Yesterday, I received user feedback about this issue and realized that Firefox's way would work ideally for my extension. Therefore, I hope the browsers will be aligned with what Firefox does.

dotproto commented 3 months ago

The behavior described for Chromium matches that engine's general handling of navigations. This behavior is described as a history manipulation intervention and was introduced in 2019. To the best of my knowledge other engines have not implemented this.

EDIT: In today's meeting @Rob--W noted that Firefox also has some history manipulation intervention.

Rob--W commented 3 months ago

EDIT: In today's meeting @Rob--W noted that Firefox also has some history manipulation intervention.

FYI in Firefox it was implemented in https://bugzilla.mozilla.org/show_bug.cgi?id=1515073, with follow-ups in https://bugzilla.mozilla.org/show_bug.cgi?id=1645211

On Firefox's side, our preference is to keep Firefox's current behavior and to allow extensions to replace history entries with the loadReplace option, as suggested in:

According to @xeenon , the disappearance of history items in Safari is a bug.

(see meeting notes for more discussion, pending review in #681).

xeenon commented 2 months ago

Thanks! We’re tracking this as a Safari bug rather than a WebKit issue. Bug reference: 134939755

mshibanami commented 2 months ago

Thanks for the responses! I now understand the differences in browser behavior, and it's good to know related issues are being addressed. I'll close this discussion. Appreciate the help!