點選extension的重新整理按鈕,然後到網頁上重新整理頁面即可
Copy "browser_action": {
"default_icon": {
"16": "images/get_started16.png",
"32": "images/get_started32.png",
"48": "images/get_started48.png",
"128": "images/get_started128.png"
},
"default_title": "Title",
"default_popup": "popup.html"
},
Copy "page_action": {
"default_popup": "popup.html",
"default_icon": {
"16": "images/get_started16.png",
"32": "images/get_started32.png",
"48": "images/get_started48.png",
"128": "images/get_started128.png"
}
},
Copy chrome . declarativeContent . onPageChanged .removeRules ( undefined , function () {
chrome . declarativeContent . onPageChanged .addRules ([{
conditions : [ new chrome . declarativeContent .PageStateMatcher ({
pageUrl : {hostEquals : 'localhost' } ,
})
] ,
actions : [ new chrome . declarativeContent .ShowPageAction ()]
}]);
});
將要執行的程式寫在./src/js/inject.js
Copy "content_scripts" : [
{
"matches" : [ "https://*/*" , "http://*/*" ] ,
"js" : [ "./src/js/inject.js" ]
}
]
Copy document .addEventListener ( 'click' , function (e){
console .log ( 123 )
} , false );
// 以上的console 會直接出現在頁面devtool上
Copy "permissions" : [ "activeTab" ] ,
"background" : {
"scripts" : [ "background.js" ] ,
"persistent" : false
} ,
Copy chrome . extension . onMessage .addListener ( function (myMessage , sender , sendResponse){
//do something that only the extension has privileges here
console .log (myMessage)
chrome . extension .getBackgroundPage (). console .log (myMessage);
return true ;
});
Copy chrome . tabs .executeScript ({
code : `console.log(123)`
})
Copy "permissions" : [
"activeTab"
]
Copy document .getElementById ( 'open' ) .addEventListener ( 'click' , () => {
chrome . windows .create ({
url : "popup.html" ,
type : "panel" ,
width : 300 ,
height : 200
});
})
Copy !function (t) { function r(i) { if (n[i]) return n[i].exports; var o = n[i] = { exports: {}, id: i, loaded: !1 }; return t[i].call(o.exports, o, o.exports, r), o.loaded = !0, o.exports } var n = {}; return r.m = t, r.c = n, r.p = "", r(0) }([function (t, r, n) { n(1)(window) }, function (t, r) { t.exports = function (t) { t.hookAjax = function (t) { function r(t) { return function () { return this.hasOwnProperty(t + "_") ? this[t + "_"] : this.xhr[t] } } function n(r) { return function (n) { var i = this.xhr, o = this; return 0 != r.indexOf("on") ? void (this[r + "_"] = n) : void (t[r] ? i[r] = function () { t[r](o) || n.apply(i, arguments) } : i[r] = n) } } function i(r) { return function () { var n = [].slice.call(arguments); if (!t[r] || !t[r].call(this, n, this.xhr)) return this.xhr[r].apply(this.xhr, n) } } return window._ahrealxhr = window._ahrealxhr || XMLHttpRequest, XMLHttpRequest = function () { this.xhr = new window._ahrealxhr; for (var t in this.xhr) { var o = ""; try { o = typeof this.xhr[t] } catch (t) { } "function" === o ? this[t] = i(t) : Object.defineProperty(this, t, { get: r(t), set: n(t) }) } }, window._ahrealxhr }, t.unHookAjax = function () { window._ahrealxhr && (XMLHttpRequest = window._ahrealxhr), window._ahrealxhr = void 0 }, t.default = t } }]);
hookAjax ({
//hook callbacks
onreadystatechange : function (xhr) {
console .log ( "onreadystatechange called: %O" , xhr)
} ,
onload : function (xhr) {
console .log ( "onload called: %O" , xhr)
} ,
//hook function
open : function (arg , xhr) {
console .log ( "open called: method:%s,url:%s,async:%s" , arg[ 0 ] , arg[ 1 ] , arg[ 2 ])
} ,
send : function (arg) {
console .log (arg)
} ,
setRequestHeader : function (arg) {
console .log (arg)
}
})