How to test a Greasemonkey script, especially on a local copy of a webpage?

删除回忆录丶 提交于 2019-12-09 12:33:25

问题


I have my own javascript that I need to test with Greasemonkey. I've never worked with Greasemonkey before; How do I test the script?

I am not testing it on the World Wide Web, I have saved the target page (Firefox > Save page as > Web page, complete), so I am testing it locally.

What is the process? How do I test the script?


回答1:


Here are some guidelines for troubleshooting Greasemonkey scripts, both in general, and on local copies of webpages.

  1. For testing on local pages (without a local web-server), you must change a setting of Greasemonkey.
    Open about:config and set greasemonkey.fileIsGreaseable to true

  2. Make sure the local copy of the webpage is not in the system's /tmp or /temp folder(s). The script will not work reliably, if it is.

  3. Make sure the script source is not in the system's /tmp or /temp folder(s). The script will not install if it is.

  4. For a script to work on local files, be sure you have an appropriate @include directive aimed at the local webpage copy. For example:

    // @include file:///D:/web/local%20page%20copies/*
    
  5. Familiarize yourself with Firefox's error console (CtrlShiftJ) and how it can be used to determine the source of errors in Greasemonkey scripts.

  6. Install Firebug and get familiar with it. Firebug's excellent console functions work great from within a GM script -- although you might have to preface them with unsafeWindow..

  7. Test as much of the javascript as you can, that doesn't use GM_ functions, in Firebug's JavaScript console first.


See also:

  • Troubleshooting for Script Authors
  • Avoid Common Pitfalls in Greasemonkey


来源:https://stackoverflow.com/questions/11836739/how-to-test-a-greasemonkey-script-especially-on-a-local-copy-of-a-webpage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!