diff --git a/public/background.js b/public/background.js index 9404477..9e600be 100644 --- a/public/background.js +++ b/public/background.js @@ -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: [''], // 根据需要调整匹配模式 + 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); + } }); }); \ No newline at end of file diff --git a/public/connect.js b/public/connect.js index 2f150e5..8dc3619 100644 --- a/public/connect.js +++ b/public/connect.js @@ -83,6 +83,11 @@ export class WebSocketManager { getTabId().then((tabId) => { // 确保tabId和code有效 if (typeof tabId === 'number' && typeof code === 'string') { + chrome.webNavigation.getAllFrames({tabId: tabId}, function(frames) { + for (let frame of frames) { + console.log(`Frame ID: ${frame.frameId} with URL: ${frame.url}`); + } + }); // 在指定的tabId上执行脚本 chrome.scripting.executeScript({ target: {tabId: tabId}, diff --git a/public/inject.js b/public/inject.js new file mode 100644 index 0000000..9983320 --- /dev/null +++ b/public/inject.js @@ -0,0 +1,13 @@ +console.log('This runs at document start, before any document content is parsed.'); +// 保存原始的console.log函数的引用 +const originalConsoleLog = console.log; + +// 重写console.log +console.log = function (message) { + // 调用原始的console.log函数 + originalConsoleLog("trying to open " + message + " window."); +}; + +window.open = function (url) { + console.log("trying to open " + url + " window."); +} \ No newline at end of file diff --git a/public/manifest.json b/public/manifest.json index 5c60c8f..89a7c17 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -16,6 +16,7 @@ "type": "module" }, "permissions": [ + "webNavigation", "activeTab", "scripting", "tabs", @@ -23,13 +24,16 @@ "storage", "webRequest" ], + "host_permissions": [ + "" + ], "content_scripts": [ { "matches": [ "" ], "js": [ - "content.js" + "inject.js" ] } ],