inject script

This commit is contained in:
go0p
2024-05-08 14:48:02 +08:00
parent fbe662c056
commit c6234ae79c
4 changed files with 36 additions and 4 deletions
+13 -3
View File
@@ -52,8 +52,18 @@ chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
}
})
chrome.tabs.query({}, (tabs) => {
tabs.forEach(function (tab) {
console.log("Tab ID",tab.id); // 输出每个标签页的ID
chrome.runtime.onInstalled.addListener(() => {
chrome.scripting.registerContentScripts([{
id: 'myScript',
matches: ['<all_urls>'], // 根据需要调整匹配模式
js: ['inject.js'],
runAt: 'document_start'
}], (result) => {
if (chrome.runtime.lastError) {
console.error(`Error registering script: ${chrome.runtime.lastError.message}`);
} else {
console.log('Script registered', result);
}
});
});