开发者

Cross browser console.log for greasemonkey/chrome userscripts

开发者 https://www.devze.com 2023-03-16 11:19 出处:网络
How do you go about using console.log in greasemonkey scripts? I don\'t get any output. // ==UserScript==

How do you go about using console.log in greasemonkey scripts? I don't get any output.

// ==UserScript==
// @name          test
// @namespace     test
// @descr开发者_开发技巧iption   test
// @require       https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js
// @version       1.2
// ==/UserScript==

console.log('test');

I get the impression that you can use console.log normally in Chrome. Is there a nice wrapper so you can log to console in both Firefox and Chrome?


console.log will appear in the Error Console in Firefox (Tools -> Error Console OR CTRL+SHIFT+J)

Changing it to unsafeWindow.console.log will make the log appear in Firebug. Make sure you read up on security concerns of unsafeWindow before using it.

The other option to get the log to appear in Firebug, as you said, is to leave it as console.log but turn on extensions.firebug.showChromeErrors AND extensions.firebug.showChromeMessages. This can be done by typing about:config in the Firefox address bar. Then filter for Chrome. Find the two options and double click them to turn them on.

All Firefox examples are for Firefox 5.0


It seems that console.log does in fact work in both Chrome and Firefox.

In Firefox you need to have Show Chrome messages and Show Chrome errors enabled in Firebug to be able to see messages produced by your greasemonkey script.

0

精彩评论

暂无评论...
验证码 换一张
取 消