mirror of
https://github.com/yaklang/yaklang-chrome-extension.git
synced 2026-09-22 03:10:43 +08:00
inject script
This commit is contained in:
+13
-3
@@ -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);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -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},
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
"type": "module"
|
||||
},
|
||||
"permissions": [
|
||||
"webNavigation",
|
||||
"activeTab",
|
||||
"scripting",
|
||||
"tabs",
|
||||
@@ -23,13 +24,16 @@
|
||||
"storage",
|
||||
"webRequest"
|
||||
],
|
||||
"host_permissions": [
|
||||
"<all_urls>"
|
||||
],
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": [
|
||||
"<all_urls>"
|
||||
],
|
||||
"js": [
|
||||
"content.js"
|
||||
"inject.js"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user