don't trust location.href as it hides text fragment
This commit is contained in:
parent
2a12cbdf43
commit
a780ecae67
|
@ -8,6 +8,7 @@
|
||||||
stringAsRegExp
|
stringAsRegExp
|
||||||
styleCodeEmpty
|
styleCodeEmpty
|
||||||
styleSectionGlobal
|
styleSectionGlobal
|
||||||
|
tabManager
|
||||||
tryRegExp
|
tryRegExp
|
||||||
URLS
|
URLS
|
||||||
*/
|
*/
|
||||||
|
@ -148,6 +149,10 @@ const styleManager = API.styles = (() => {
|
||||||
/** @returns {Promise<StyleSectionsToApply>} */
|
/** @returns {Promise<StyleSectionsToApply>} */
|
||||||
async getSectionsByUrl(url, id, isInitialApply) {
|
async getSectionsByUrl(url, id, isInitialApply) {
|
||||||
await ready;
|
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);
|
let cache = cachedStyleForUrl.get(url);
|
||||||
if (!cache) {
|
if (!cache) {
|
||||||
cache = {
|
cache = {
|
||||||
|
|
|
@ -8,9 +8,9 @@ const tabManager = (() => {
|
||||||
chrome.tabs.onRemoved.addListener(tabId => cache.delete(tabId));
|
chrome.tabs.onRemoved.addListener(tabId => cache.delete(tabId));
|
||||||
chrome.tabs.onReplaced.addListener((added, removed) => cache.delete(removed));
|
chrome.tabs.onReplaced.addListener((added, removed) => cache.delete(removed));
|
||||||
navigatorUtil.onUrlChange(({tabId, frameId, url}) => {
|
navigatorUtil.onUrlChange(({tabId, frameId, url}) => {
|
||||||
|
const oldUrl = !frameId && tabManager.get(tabId, 'url', frameId);
|
||||||
|
tabManager.set(tabId, 'url', frameId, url);
|
||||||
if (frameId) return;
|
if (frameId) return;
|
||||||
const oldUrl = tabManager.get(tabId, 'url');
|
|
||||||
tabManager.set(tabId, 'url', url);
|
|
||||||
for (const fn of listeners) {
|
for (const fn of listeners) {
|
||||||
try {
|
try {
|
||||||
fn({tabId, url, oldUrl});
|
fn({tabId, url, oldUrl});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user