MCPcopy
hub / github.com/darkreader/darkreader / getTabURL

Method getTabURL

src/background/tab-manager.ts:370–406  ·  view source on GitHub ↗
(tab: chrome.tabs.Tab | null)

Source from the content-addressed store, hash-verified

368 }
369
370 static async getTabURL(tab: chrome.tabs.Tab | null): Promise<string> {
371 if (__CHROMIUM_MV3__) {
372 if (!tab) {
373 return 'about:blank';
374 }
375 try {
376 return (await chrome.tabs.get(tab.id!)).url || 'about:blank';
377 } catch (e) {
378 try {
379 return (await chrome.scripting.executeScript({
380 target: {
381 tabId: tab.id!,
382 frameIds: [0],
383 },
384 world: 'MAIN',
385 injectImmediately: true,
386 func: () => window.location.href,
387 }))[0].result || 'about:blank';
388 } catch (e) {
389 const errMessage = String(e);
390 if (
391 errMessage.includes('chrome://') ||
392 errMessage.includes('chrome-extension://') ||
393 errMessage.includes('gallery')
394 ) {
395 return 'chrome://protected';
396 }
397 return 'about:blank';
398 }
399 }
400 }
401 // It can happen in cases whereby the tab.url is empty.
402 // Luckily this only and will only happen on `about:blank`-like pages.
403 // Due to this we can safely use `about:blank` as fallback value.
404 // In some extraordinary circumstances tab may be undefined.
405 return tab && tab.url || 'about:blank';
406 }
407
408 static async updateContentScript(options: {runOnProtectedPages: boolean}): Promise<void> {
409 (await queryTabs({discarded: false}))

Callers 3

sendMessageMethod · 0.80
getActiveTabURLMethod · 0.80
getActiveTabInfoMethod · 0.80

Calls 1

getMethod · 0.65

Tested by

no test coverage detected