Code: Select all
chrome.action.onClicked.addListener(() => {
const uri = chrome.runtime.getURL("index.html");
chrome.tabs.query({}, async (tabs) => {
const existingTab = tabs.find((tab) => tab.url === uri);
if (existingTab && existingTab.id) {
await chrome.tabs.update(existingTab.id, {
active: true,
});
return;
}
chrome.tabs.create({ url: uri });
});
});
Ich verwende chrome.runtime.create({}), um einen Port aus meinen Inhaltsskripten zu erstellen. Ich habe viele Dinge ausprobiert, aber keines hat es gelöst.
Wenn es darauf ankommt, verwende ich Webpack, um die Erweiterung zu erstellen.