Skip to content

Commit

Permalink
update: catch inject error
Browse files Browse the repository at this point in the history
  • Loading branch information
yamadashy committed May 18, 2024
1 parent 35ab9f0 commit 3e63b1c
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions app/scripts/background.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,52 @@
// Update extension content for slack tabs
chrome.tabs.query({}, async (tabs) => {
for (const tabKey in tabs) {
const tab = tabs[tabKey];

// Do not have permission
if (tab.url === undefined) {
continue;
}
const injectContentToTab = async (tab: chrome.tabs.Tab) => {
// Do not have permission
if (tab.url === undefined) {
return;
}

// Skip execute on discarded tab
if (tab.discarded) {
continue;
}
// Skip execute on discarded tab
if (tab.discarded) {
return;
}

// Under some circumstances a Tab may not be assigned an ID
if (tab.id === undefined) {
continue;
}
// Under some circumstances a Tab may not be assigned an ID
if (tab.id === undefined) {
return;
}

const manifest = chrome.runtime.getManifest();
const cssFiles = manifest.content_scripts?.[0].css ?? [];
const jsFiles = manifest.content_scripts?.[0].js ?? [];
const manifest = chrome.runtime.getManifest();
const cssFiles = manifest.content_scripts?.[0].css ?? [];
const jsFiles = manifest.content_scripts?.[0].js ?? [];

if (cssFiles.length > 0) {
await chrome.scripting.insertCSS({
target: {
tabId: tab.id,
allFrames: true,
},
files: cssFiles,
});
chrome.scripting.executeScript({
}
if (jsFiles.length > 0) {
await chrome.scripting.executeScript({
target: {
tabId: tab.id,
allFrames: true,
},
files: jsFiles,
});
}
};

// Update extension content for tabs
chrome.tabs.query({}, async (tabs) => {
for (const tabKey in tabs) {
const tab = tabs[tabKey];

try {
injectContentToTab(tab);
} catch (e) {
console.error(e);
}
}
});

0 comments on commit 3e63b1c

Please sign in to comment.