MCPcopy
hub / github.com/darkreader/darkreader / getExtensionPageTabMV3

Function getExtensionPageTabMV3

src/ui/utils.ts:151–172  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

149// This function should have reasonable performance since it sends
150// messages only to popups and not regular windows.
151async function getExtensionPageTabMV3(): Promise<chrome.tabs.Tab | null> {
152 return new Promise((resolve) => {
153 chrome.windows.getAll({
154 populate: true,
155 windowTypes: ['popup'],
156 }, (w) => {
157 const responses: Array<Promise<string>> = [];
158 let found = false;
159 for (const window of w) {
160 const response = chrome.tabs.sendMessage<string, 'getExtensionPageTabMV3_pong'>(window.tabs![0]!.id!, 'getExtensionPageTabMV3_ping', {frameId: 0});
161 response.then((response) => {
162 if (response === 'getExtensionPageTabMV3_pong') {
163 found = true;
164 resolve(window.tabs![0]);
165 }
166 });
167 responses.push(response);
168 }
169 Promise.all(responses).then(() => !found && resolve(null));
170 });
171 });
172}
173
174async function getExtensionPageTab(url: string): Promise<chrome.tabs.Tab | null> {
175 if (__CHROMIUM_MV3__) {

Callers 1

getExtensionPageTabFunction · 0.85

Calls 2

sendMessageMethod · 0.80
allMethod · 0.80

Tested by

no test coverage detected