-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
28 lines (27 loc) · 949 Bytes
/
background.js
File metadata and controls
28 lines (27 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
chrome.action.onClicked.addListener((tab) => {
chrome.tabs.sendMessage(tab.id, {action: "toggleExtension"});
});
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "error") {
console.error('Error in Responsive Design Checker:', request.error);
}
if (request.action === "getPageContent") {
chrome.tabs.get(request.tabId, (tab) => {
if (chrome.runtime.lastError) {
sendResponse({error: "Tab not found"});
return;
}
chrome.scripting.executeScript({
target: {tabId: request.tabId},
function: () => document.documentElement.outerHTML
}, (result) => {
if (chrome.runtime.lastError) {
sendResponse({error: chrome.runtime.lastError.message});
} else {
sendResponse({content: result[0].result});
}
});
});
return true; // Indicates that the response is sent asynchronously
}
});