Похоже, что использование фонового работника может быть потенциальным решением, особенно со следующей конфигурацией:
Код: Выделить всё
"background": {
"service_worker": "background.js"
}
Вот текущее содержимое файла background.js:
Код: Выделить всё
browser.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
// Only run when the page has fully loaded
if (changeInfo.status === 'complete') {
// Check if the URL meets the criteria
const shouldInject = await checkUrlAgainstApi(tab.url);
if (shouldInject) {
// Inject content script manually
browser.scripting.executeScript({
target: { tabId },
files: ['content.js']
});
}
}
});
async function checkUrlAgainstApi(url) {
console.log('Allowing script injection for: ' + url);
return true;
}
Код: Выделить всё
{
"manifest_version": 3,
"name": "Sample",
"version": "1.0",
"description": "Sample",
"permissions": [
"activeTab",
"tabs"
],
"host_permissions": [
"http://*/*",
"https://*/*"
],
"background": {
"scripts": [
"background.js"
]
},
"content_scripts": [
{
"matches": [
""
],
"js": [
"content.js"
],
"css": [
"styles.css"
]
}
]
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... quiring-us
Мобильная версия