javascript - 如何杀死 Chrome 开发者工具中的警告框?
问题描述
示例js:
如何在 chrome 开发人员工具中杀死警报框?
在 content_scripts -> content.js
window.onload = function () {
window.alert = function () {}
}
但没有效果,帮帮我。
解决方案
清单.json
"content_scripts": [
{
"matches": [
"http://elearn.ecust.edu.cn:86/*"
],
"js": [
"inject.js"
],
"run_at": "document_start",
"all_frames": true
}
],
注入.js
window.addEventListener("DOMContentLoaded", function () {
console.log("----加载inject.js---DOMContentLoaded")
window.alert = function () { }
overrideSelectNativeJS_Functions()
})
window.addEventListener("load", function () {
console.log("----加载inject.js---load")
window.alert = function () { }
overrideSelectNativeJS_Functions()
})
window.addEventListener("beforeunload", function () {
console.log("----加载inject.js---beforeunload")
window.alert = function () { }
overrideSelectNativeJS_Functions()
})
window.addEventListener("unload", function () {
console.log("----加载inject.js---unload")
window.alert = function () { }
overrideSelectNativeJS_Functions()
})
addJS_Node(null, null, overrideSelectNativeJS_Functions);
function overrideSelectNativeJS_Functions() {
window.alert = function alert(message) {
console.log(message);
}
}
function addJS_Node(text, s_URL, funcToRun) {
var D = document;
var scriptNode = D.createElement('script');
scriptNode.type = "text/javascript";
if (text) scriptNode.textContent = text;
if (s_URL) scriptNode.src = s_URL;
if (funcToRun) scriptNode.textContent = '(' + funcToRun.toString() + ')()';
var targ = D.getElementsByTagName('head')[0] || D.body || D.documentElement;
targ.appendChild(scriptNode);
}
推荐阅读
- reactjs - 使用 Apache 时,React 应用程序显示“404 找不到请求的路径”页面
- r - 如何修复 S-plus 中的线性模型拟合误差
- excel - 如何将变量从函数传递给子函数?
- typescript - 'as const' 与类型相结合?
- excel - 数据验证不会保存
- javascript - 如何正确利用 `.reduce` 来计算数组中的字符总数?
- arrays - AngularJS ng-repeat 和 indexOf() 检查对象
- java - 不明白这些位运算符如何对字节和整数进行操作
- javascript - 如何绕过输入表单安全性
- android - 带有占位符的 Android Pagination BoundaryCallback 无法正常工作?