Skip to content

Commit 3dc212c

Browse files
committed
fix: reload tab on maps or extension leaflet match
1 parent 16e12e6 commit 3dc212c

File tree

1 file changed

+7
-24
lines changed

1 file changed

+7
-24
lines changed

src/bg/action.ts

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { browserAction, webNavigation, type Tabs, tabs } from 'webextension-polyfill';
22
import { getHostname, invertHostState } from './utils/storage';
3-
import { matcher, runtimeMapUrl } from './bg';
3+
import { matcher as mapsUrlMatcher, runtimeMapUrl } from './bg';
44

55
const replacedUrlMatcher = new RegExp(`^${runtimeMapUrl}\?`);
66

@@ -9,8 +9,7 @@ const replacedUrlMatcher = new RegExp(`^${runtimeMapUrl}\?`);
99
* Takes the current tab, takes its hostname and inverts the state of the hostname.
1010
*
1111
* Requests all frames from the current tab, filters them for extension Leaflet frames and Maps frames.
12-
* Reloads the full tab on extension Leaflet frame match.
13-
* If no extension Leaflet frames were found it just reloads the Maps frames
12+
* Reloads the full tab on extension Leaflet or Maps frame match.
1413
* @param tab Currently active tab
1514
*/
1615
async function actionClick(tab: Tabs.Tab): Promise<void> {
@@ -21,29 +20,13 @@ async function actionClick(tab: Tabs.Tab): Promise<void> {
2120

2221
let frames = (await webNavigation.getAllFrames({ tabId: tab.id })) ?? [];
2322

24-
// Added instead of commented below, as map currently isn't loaded properly on just frame reload...
25-
if (frames.some((frame) => frame.url.match(replacedUrlMatcher) || frame.url.match(matcher))) {
23+
if (
24+
frames.some((frame) => {
25+
frame.url.match(replacedUrlMatcher) || frame.url.match(mapsUrlMatcher);
26+
})
27+
) {
2628
tabs.reload(tab.id, { bypassCache: true });
27-
return;
2829
}
29-
30-
// TODO: check if reusable
31-
/*
32-
// matches osm frames (just reloading the frame ist not working for some reason, so in case of replaced maps the whole tab is reloaded)
33-
if (frames.some((frame) => frame.url.match(replacedUrlMatcher))) {
34-
tabs.reload(tab.id, { bypassCache: true });
35-
return;
36-
}
37-
38-
// matches maps frames (finds the frames that have maps and reloads only them)
39-
frames = frames.filter((frame) => frame.url.match(matcher));
40-
frames.forEach((frame) => {
41-
tabs.executeScript(tab.id, {
42-
frameId: frame.frameId,
43-
code: 'document.location.reload();',
44-
});
45-
});
46-
*/
4730
}
4831

4932
browserAction.onClicked.addListener(actionClick);

0 commit comments

Comments
 (0)