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

Watch for navigation via the new Navigation API #6649

Closed
fregante opened this issue Oct 11, 2023 · 3 comments · Fixed by #7030
Closed

Watch for navigation via the new Navigation API #6649

fregante opened this issue Oct 11, 2023 · 3 comments · Fixed by #7030

Comments

@fregante
Copy link
Contributor

Browsers now have access to all navigation events thanks to the navigation API.

https://developer.mozilla.org/en-US/docs/Web/API/Navigation_API

We should drop the browser.webNavigation-based events from the background and just use the new API directly in the content script

browser.webNavigation.onHistoryStateUpdated.addListener(onNavigation);
browser.webNavigation.onReferenceFragmentUpdated.addListener(
debouncedOnNavigation
);

export async function handleNavigate({

This does not affect the pageEditor’s listeners, because you can't listen to the navigation of other frames.

Related issue:

@fregante
Copy link
Contributor Author

This would reduce the reliance on the background page and the amount of messaging required during navigation.

I'll mark this as mv3 only because it would be particularly beneficial there.

@fregante fregante added the mv3 label Oct 11, 2023
@twschiller
Copy link
Contributor

twschiller commented Oct 11, 2023

NOTE: Chromium-only (not Firefox/Safari) is OK.

Related discussion about SPA event detection: w3c/webextensions#446

This would reduce the reliance on the background page and the amount of messaging required during navigation.

Although, listening for navigation could be a good way to avoid the background worker being recycled

@fregante
Copy link
Contributor Author

listening for navigation could be a good way to avoid the background worker being recycled

If that actually helps we can keep the listeners enabled without having to also using the messaging channel. This has the added benefit that when the worker is eventually and necessarily restarted, the navigation doesn't have to wait for it to complete loading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants