Skip to content

Instantly share code, notes, and snippets.

@Mufanc
Last active May 13, 2023 00:41
Show Gist options
  • Save Mufanc/368f5c64924bfee67a35ac4494c79c34 to your computer and use it in GitHub Desktop.
Save Mufanc/368f5c64924bfee67a35ac4494c79c34 to your computer and use it in GitHub Desktop.
优化 chrome://inspect 调试
  • 打开 chrome://flags,启用:

image

  • manifest.json
{
    "manifest_version": 2,
    "name": "Refine Inspector",
    "version": "1.0.0",
    "permissions": ["<all_urls>"],
    "web_accessible_resources": ["inject.js"],
    "content_scripts": [
        {
            "matches": ["chrome://inspect/*"],
            "js": ["bridge.js"],
            "run_at": "document_start"
        }
    ]
}
  • inject.js
(function () {
    Function.prototype.bind = new Proxy(
        Function.prototype.bind, {
            apply(func, thisObj, args) {
                if (thisObj.name == 'sendTargetCommand' && args[1] == 'inspect') {
                    args[1] = 'inspect-fallback'
                }
                return Reflect.apply(func, thisObj, args)
            }
        }
    )
})()
  • bridge.js
const script = document.createElement('script');
script.src = chrome.extension.getURL('inject.js');
script.onload = function() {
    this.remove();
};
(document.head || document.documentElement).appendChild(script);
  • 上面三个文件放入同一文件夹,然后从 chrome://extensions/ 打开开发者模式,加载已解压的扩展
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment