TODO: 修正inject background的框架设计.
This commit is contained in:
15
example/.vscode/launch.json
vendored
Normal file
15
example/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "chrome",
|
||||
"request": "launch",
|
||||
"name": "Launch Chrome against localhost",
|
||||
"url": "http://www.baidu.com",
|
||||
"webRoot": "${workspaceFolder}"
|
||||
}
|
||||
]
|
||||
}
|
||||
27
example/background.js
Normal file
27
example/background.js
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
|
||||
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
|
||||
console.log(sender);
|
||||
chrome.tabs.executeScript(sender.tab.id, { runAt: "document_end", file: "task.js"}, function (results) {
|
||||
console.log(results);
|
||||
})
|
||||
sendResponse({});
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
// chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
|
||||
// console.log(request, sender);
|
||||
// });
|
||||
|
||||
chrome.webRequest.onBeforeRequest.addListener(function(details){
|
||||
if( details.url.startsWith("http://eson.config") ) {
|
||||
// console.log(details);
|
||||
var params = new URLSearchParams(details.url)
|
||||
TaskUrl = params.get("taskurl");
|
||||
chrome.tabs.remove(details.tabId, function() { });
|
||||
return {cancel: true};
|
||||
}
|
||||
},{'urls':["<all_urls>"]},['blocking']);
|
||||
|
||||
7
example/inject.js
Normal file
7
example/inject.js
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
|
||||
setTimeout(function () {
|
||||
chrome.runtime.sendMessage({}, function(resposne){
|
||||
console.log(resposne);
|
||||
})
|
||||
}, 3000);
|
||||
22
example/manifest.json
Normal file
22
example/manifest.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"background": {
|
||||
"scripts": [
|
||||
"background.js"
|
||||
]
|
||||
},
|
||||
"content_scripts": [ {
|
||||
"all_frames": true,
|
||||
"js": [
|
||||
"inject.js"
|
||||
],
|
||||
"matches": [ "<all_urls>" ],
|
||||
"run_at": "document_end"
|
||||
} ],
|
||||
"description": "block all",
|
||||
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlurgt0Ykv740tjk1ebeiSX6UVVRRhxVvh+FvRMTe9PKzkAKUDEW2IjNUz1swxZA8ILnMvtyamAfiErTOxUFB8+zCADU/CK2YEhqUJo3tmHCg6EP2XJL220ZXjmIeft1AqJV1BmGRLhm8VnH8dJ2EThfcflx4JEdlh0/aLJr6UVjF2hPVX8JLAMTVjEfiC82KDNGgXDADqBm3E/6n+Dx+3KhgIYTXKIMk+qRVaOhjAJLh8a9OrDBwpylP5RDifTAyVVa9UOyoLNqynzC9oLabWUr1ovWAOiivhYknFCXnl5q971iNSFpmjc+ZW+aK+TRjMnJF84IeA170corVG3KgnwIDAQAB",
|
||||
"manifest_version": 2,
|
||||
"name": "ChromeProxyTest",
|
||||
"permissions": ["background", "storage","tabs" , "activeTab", "webRequest", "webRequestBlocking", "<all_urls>", "webNavigation"],
|
||||
"short_name": "ChromeProxyTest",
|
||||
"version": "0.1.0"
|
||||
}
|
||||
1
example/task.js
Normal file
1
example/task.js
Normal file
@@ -0,0 +1 @@
|
||||
window.location.href = "http://www.baidu.com";
|
||||
Reference in New Issue
Block a user