Skip to content

Commit 9d67b97

Browse files
committed
more reliable urlChange
1 parent c523fea commit 9d67b97

3 files changed

Lines changed: 18 additions & 10 deletions

File tree

src/background/icon-manager.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@ onUnload.add((tabId, frameId, port) => {
6767
/**
6868
* @param {(number|string)[]} styleIds
6969
* @param {boolean} [lazyBadge] preventing flicker during page load
70+
* @param {number} [iid] instance id
7071
*/
71-
export function updateIconBadge(styleIds, lazyBadge) {
72+
export function updateIconBadge(styleIds, lazyBadge, iid) {
7273
// FIXME: in some cases, we only have to redraw the badge. is it worth a optimization?
7374
const {tab: {id: tabId}, TDM} = this.sender;
7475
const frameId = TDM > 0 ? 0 : this.sender.frameId;
7576
const value = styleIds.length ? styleIds.map(Number) : undefined;
7677
tabMan.set(tabId, kStyleIds, frameId, value);
78+
if (iid) tabMan.set(tabId, 'iid', frameId, value && iid);
7779
debounce(refreshStaleBadges, frameId && lazyBadge ? 250 : 0);
7880
staleBadges.add(tabId);
7981
if (!frameId) refreshIcon(tabId, true);

src/background/navigation-manager.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,18 @@ async function onNavigation(navType, data) {
4949
const {tabId} = data;
5050
const td = tabCache[tabId];
5151
if (td && navType !== kCommitted) {
52-
const {frameId: f, documentId: d, frameType, url} = data;
53-
const isTop = !frameType && !f || frameType === 'outer_frame';
54-
const oldUrl = td[kUrl]?.[f];
55-
if (oldUrl !== url)
56-
sendTab(tabId, {method: 'urlChanged', top: isTop, old: oldUrl, url},
57-
__.MV3 || d ? {documentId: d} : {frameId: f});
52+
const {frameId: f, url} = data;
53+
if (td[kUrl]?.[f] !== url) {
54+
const {documentId: d, frameType} = data;
55+
sendTab(tabId, {
56+
method: 'urlChanged',
57+
top: !frameType && !f || frameType === 'outer_frame',
58+
iid: !__.MV3 && td.iid?.[f] || 0,
59+
url,
60+
}, __.MV3 || d
61+
? {documentId: d}
62+
: {frameId: f});
63+
}
5864
}
5965
for (const fn of onUrlChange) fn(data, navType);
6066
}

src/content/apply.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if (isFrame) {
2121
const isFrameNoUrl = isFrameSameOrigin && location.protocol === 'about:';
2222

2323
/** Polyfill for documentId in Firefox and Chrome pre-106 */
24-
const instanceId = (FF || !__.MV3 && !CSS.supports('top', '1ic')) && Math.random() || undefined;
24+
const instanceId = (FF || !__.MV3 && !CSS.supports('top', '1ic')) && Math.random() || 0;
2525
/** about:blank iframes are often used by sites for file upload or background tasks,
2626
* and they may break if unexpected DOM stuff is present at `load` event
2727
* so we'll add the styles only if the iframe becomes visible */
@@ -163,7 +163,7 @@ function applyOnMessage(req, sender, multi) {
163163
break;
164164

165165
case 'urlChanged':
166-
if (matchUrl === req.old)
166+
if (req.iid === instanceId)
167167
updateUrl(req.url);
168168
break;
169169

@@ -227,7 +227,7 @@ function updateCount() {
227227
if (isUnstylable) API.styleViaAPI({method: 'updateCount'});
228228
else if (!throttled
229229
&& throttledCount !== (str = (ids = [...styleInjector.table.keys()]).join(','))) {
230-
API.updateIconBadge(ids, lazyBadge);
230+
API.updateIconBadge(ids, lazyBadge, instanceId);
231231
throttledCount = str;
232232
}
233233
}

0 commit comments

Comments
 (0)