Content script interaction with history.pushState()

NEW
Unassigned

Status

()

Toolkit
WebExtensions: General
P2
normal
2 months ago
2 months ago

People

(Reporter: zombie, Unassigned)

Tracking

57 Branch
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

2 months ago
Use case:

1) Extensions has content script for "example.com/foo".
2) user opens "example.com" which does history.pushState("/foo")

result: content script not inserted.

What's worse, there is no in-content event for pushState(), so the extension can't have a content script for all of "example.com/*" and check the page url + listen for change events.

(supposedly, there is a spec proposal for this, which I'll link if I can figure out where to look for it)
(Reporter)

Comment 1

2 months ago
Unfortunately, I don't see a great answer here.

We probably _could_ listen for history changes, and inject the content script once the page does pushState("/foo"), but what happens when it then does pushState("/bar")?  Do we *also* load scripts for "example.com/bar"?  What if they conflict and were not meant to work together?


The new history event and letting extensions sort it out themselves seems like the least bad option.

Comment 2

2 months ago
I tend to agree, an extension should already be able to listen for history events using webNavigation.onHistoryStateUpdated
(and by combining this webNavigation event and the WebExtensions messaging API, the extension can ask its content script to do something in response)

Updated

2 months ago
Priority: -- → P2
You need to log in before you can comment on or make changes to this bug.