-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
36 lines (27 loc) · 977 Bytes
/
background.js
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
29
30
31
32
33
34
35
36
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){
});
// chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) {
// chrome.tabs.executeScript(tab.id, {file: "program.js"});
// });
chrome.runtime.onMessage.addListener(function(message, sender, response) {
if(message.loadURLNewTab){
let newUrl = message.loadURLNewTab;
chrome.tabs.create({ url: newUrl });
}
else if (message.loadURL) {
let newUrl = message.loadURL;
chrome.tabs.update(sender.tab.id, {url: newUrl})
}
});
async function getCurrentTab() {
let queryOptions = { active: true, currentWindow: true };
let [tab] = await chrome.tabs.query(queryOptions);
return tab;
}
chrome.runtime.onInstalled.addListener(async () => {
console.log(await getCurrentTab())
chrome.scripting.executeScript({
target: {tabId: (await getCurrentTab()).id},
files: ['program.js']
});
});