Skip to content

Commit 9f2983b

Browse files
authored
Disable clipper button on unclippable pages (#568)
* Disable on unclippable pages * Updated the code to make it generic for any browser * Added lint fixes
1 parent 28ecef3 commit 9f2983b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/scripts/extensions/webExtensionBase/webExtension.ts

+20
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class WebExtension extends ExtensionBase<WebExtensionWorker, W3CTab, numb
4646
this.registerContextMenuItems();
4747
});
4848
this.registerInstallListener();
49+
this.registerTabCreateOrUpdateListener();
4950
this.registerTabRemoveListener();
5051
}
5152

@@ -242,6 +243,25 @@ export class WebExtension extends ExtensionBase<WebExtensionWorker, W3CTab, numb
242243
});
243244
}
244245

246+
private registerTabCreateOrUpdateListener() {
247+
const matchesAnyUnclippablePage = (url) => {
248+
const unclippablePages = ["chrome://*", "edge://*"];
249+
return unclippablePages.some(unclippablePage => url.match(unclippablePage));
250+
};
251+
252+
WebExtension.browser.tabs.onCreated.addListener((tab: W3CTab) => {
253+
if (matchesAnyUnclippablePage(tab.url)) {
254+
WebExtension.browser.action.disable(tab.id);
255+
}
256+
});
257+
258+
WebExtension.browser.tabs.onUpdated.addListener((tabId: number, changeInfo: any, tab: W3CTab) => {
259+
if (matchesAnyUnclippablePage(tab.url)) {
260+
WebExtension.browser.action.disable(tabId);
261+
}
262+
});
263+
}
264+
245265
private onInstalledSupported(): boolean {
246266
return !!WebExtension.browser.runtime.onInstalled;
247267
}

0 commit comments

Comments
 (0)