Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions plugin/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,25 +241,29 @@ var main = (function() {
}
}

function injectContentScript(tabId) {
async function injectContentScript(tabId) {
// Checking for firefox here because `browser.*` requires minimum chrome version 148
const tab = util.isFirefox()
? await browser.tabs.get(tabId)
: await chrome.tabs.get(tabId);

const cannotReadUrl = !tab.url;
if (cannotReadUrl) {
return;
}

if (util.isFirefox()) {
return Firefox.injectContentScript(tabId);
} else {
chromeInjectContentScript(tabId);
return chromeInjectContentScript(tabId);
}
}

function chromeInjectContentScript(tabId) {
try {
chrome.scripting.executeScript({
target: {tabId: tabId},
files: ["js/ContentScript.js"]
});
} catch {
if (chrome.runtime.lastError) {
util.log(chrome.runtime.lastError.message);
}
}
return chrome.scripting.executeScript({
target: {tabId: tabId},
files: ["js/ContentScript.js"],
});
}

function populateControls() {
Expand Down
Loading