-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.js
More file actions
21 lines (21 loc) · 741 Bytes
/
background.js
File metadata and controls
21 lines (21 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
chrome.action.onClicked.addListener((tab) => {
if (tab.url.includes("hackerrank.com")) {
chrome.tabs.sendMessage(tab.id, { action: "scrape" }, (response) => {
if (chrome.runtime.lastError) {
console.error(
"Error sending message to content script:",
chrome.runtime.lastError,
);
alert("An error occurred. Please check the console for details.");
} else if (response && response.success) {
alert(response.message);
} else if (response) {
alert("Error: " + response.message);
} else {
alert("No response from the page. Please refresh and try again.");
}
});
} else {
alert("This extension works only on hackerrank.com");
}
});