diff --git a/background/style-manager.js b/background/style-manager.js index 03376874..c9497288 100644 --- a/background/style-manager.js +++ b/background/style-manager.js @@ -8,6 +8,7 @@ stringAsRegExp styleCodeEmpty styleSectionGlobal + tabManager tryRegExp URLS */ @@ -148,6 +149,10 @@ const styleManager = API.styles = (() => { /** @returns {Promise} */ async getSectionsByUrl(url, id, isInitialApply) { await ready; + /* Chrome hides text frament from location.href of the page e.g. #:~:text=foo + so we'll use the real URL reported by webNavigation API */ + const {tab, frameId} = this.sender; + url = tab && tabManager.get(tab.id, 'url', frameId) || url; let cache = cachedStyleForUrl.get(url); if (!cache) { cache = { diff --git a/background/tab-manager.js b/background/tab-manager.js index 49061fcf..5a341c1f 100644 --- a/background/tab-manager.js +++ b/background/tab-manager.js @@ -8,9 +8,9 @@ const tabManager = (() => { chrome.tabs.onRemoved.addListener(tabId => cache.delete(tabId)); chrome.tabs.onReplaced.addListener((added, removed) => cache.delete(removed)); navigatorUtil.onUrlChange(({tabId, frameId, url}) => { + const oldUrl = !frameId && tabManager.get(tabId, 'url', frameId); + tabManager.set(tabId, 'url', frameId, url); if (frameId) return; - const oldUrl = tabManager.get(tabId, 'url'); - tabManager.set(tabId, 'url', url); for (const fn of listeners) { try { fn({tabId, url, oldUrl});