Skip to content

Commit

Permalink
fix: reload tab on maps or extension leaflet match
Browse files Browse the repository at this point in the history
  • Loading branch information
nobkd committed Jul 14, 2023
1 parent 16e12e6 commit 3dc212c
Showing 1 changed file with 7 additions and 24 deletions.
31 changes: 7 additions & 24 deletions src/bg/action.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { browserAction, webNavigation, type Tabs, tabs } from 'webextension-polyfill';
import { getHostname, invertHostState } from './utils/storage';
import { matcher, runtimeMapUrl } from './bg';
import { matcher as mapsUrlMatcher, runtimeMapUrl } from './bg';

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

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

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

// Added instead of commented below, as map currently isn't loaded properly on just frame reload...
if (frames.some((frame) => frame.url.match(replacedUrlMatcher) || frame.url.match(matcher))) {
if (
frames.some((frame) => {
frame.url.match(replacedUrlMatcher) || frame.url.match(mapsUrlMatcher);
})
) {
tabs.reload(tab.id, { bypassCache: true });
return;
}

// TODO: check if reusable
/*
// matches osm frames (just reloading the frame ist not working for some reason, so in case of replaced maps the whole tab is reloaded)
if (frames.some((frame) => frame.url.match(replacedUrlMatcher))) {
tabs.reload(tab.id, { bypassCache: true });
return;
}
// matches maps frames (finds the frames that have maps and reloads only them)
frames = frames.filter((frame) => frame.url.match(matcher));
frames.forEach((frame) => {
tabs.executeScript(tab.id, {
frameId: frame.frameId,
code: 'document.location.reload();',
});
});
*/
}

browserAction.onClicked.addListener(actionClick);

0 comments on commit 3dc212c

Please sign in to comment.