“Un-redefining” Google Chrome's console Object

后端 未结 7 743
失恋的感觉
失恋的感觉 2020-12-31 06:58

I\'m dealing with a system where the following Javascript code (which is out of my control) is being executed early in the page

if (!(\"console\" in window)          


        
7条回答
  •  旧巷少年郎
    2020-12-31 07:18

    You could write a pretty basic userscript to assign console as suggested above. Then go into the manifest.json for that userscript, and change the run_at setting (see http://code.google.com/chrome/extensions/content_scripts.html ) to document_start. That will make the userscript now run before any of the page scripts run, so before console ever gets messed with.

    ...edit...

    Actually, I note from http://blog.chromium.org/2011/07/chrome-extensions-now-with-more.html that chrome also now supports @run-at, so you can set that, and don't even have to mess with manifest.json directly. They have an example script using @run-at at document_start at http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/howto/userscript-runat/runat.user.js?view=markup

提交回复
热议问题