(onlyUpdateActiveTab = false)
| 445 | // and not just that tab as Dark Reader currently doesn't have per-tab operations, |
| 446 | // this should be the expected behavior. |
| 447 | static async sendMessage(onlyUpdateActiveTab = false): Promise<void> { |
| 448 | TabManager.timestamp++; |
| 449 | |
| 450 | const activeTabHostname = onlyUpdateActiveTab ? getURLHostOrProtocol(await TabManager.getActiveTabURL()) : null; |
| 451 | |
| 452 | (await queryTabs({discarded: false})) |
| 453 | .filter((tab) => Boolean(TabManager.tabs[tab.id!])) |
| 454 | .forEach((tab) => { |
| 455 | const frames = TabManager.tabs[tab.id!]; |
| 456 | Object.entries(frames) |
| 457 | .filter(([, {state}]) => state === DocumentState.ACTIVE || state === DocumentState.PASSIVE) |
| 458 | .forEach(async ([id, {url, documentId, scriptId, isTop}]) => { |
| 459 | const frameId = Number(id); |
| 460 | const tabURL = await TabManager.getTabURL(tab); |
| 461 | |
| 462 | // Check if hostname are equal when we only want to update active tab. |
| 463 | if (onlyUpdateActiveTab && getURLHostOrProtocol(tabURL) !== activeTabHostname) { |
| 464 | return; |
| 465 | } |
| 466 | |
| 467 | const message = TabManager.getTabMessage(tabURL, url!, isTop || false); |
| 468 | message.scriptId = scriptId; |
| 469 | |
| 470 | if (tab.active && isTop) { |
| 471 | TabManager.sendDocumentMessage(tab!.id!, documentId!, message, frameId); |
| 472 | } else { |
| 473 | setTimeout(() => { |
| 474 | TabManager.sendDocumentMessage(tab!.id!, documentId!, message, frameId); |
| 475 | }); |
| 476 | } |
| 477 | if (TabManager.tabs[tab.id!][frameId]) { |
| 478 | TabManager.tabs[tab.id!][frameId].timestamp = TabManager.timestamp; |
| 479 | } |
| 480 | }); |
| 481 | }); |
| 482 | } |
| 483 | |
| 484 | static canAccessTab(tab: chrome.tabs.Tab | null): boolean { |
| 485 | return tab && Boolean(TabManager.tabs[tab.id!]) || false; |
no test coverage detected