【发布时间】:2012-12-13 02:28:26
【问题描述】:
有什么方法可以在 Chrome 的 JavaScript 控制台中使用 Tampermonkey's API 吗?
我想弄乱GM_xmlhttpRequest() 和GM_listValues() 之类的函数。
【问题讨论】:
标签: javascript google-chrome console google-chrome-devtools tampermonkey
有什么方法可以在 Chrome 的 JavaScript 控制台中使用 Tampermonkey's API 吗?
我想弄乱GM_xmlhttpRequest() 和GM_listValues() 之类的函数。
【问题讨论】:
标签: javascript google-chrome console google-chrome-devtools tampermonkey
创建以下脚本:
// ==UserScript==
// @name Exports some GM functions
// @namespace Whatever
// @match *
// ==/UserScript==
// WARNING: Any page can now use these methods! Be careful,
// or change "@match *" to "@match https://example.com" and
// visit https://example.com to test the API.
unsafeWindow.GM_xmlhttpRequest = GM_xmlhttpRequest;
unsafeWindow.GM_listValues = GM_listValues;
打开任何可以激活 Tampermonkey 的页面(例如 https://stackoverflow.com/)。
【讨论】:
chrome://extensions/ 以找出您正在寻找的扩展程序的 extensionID (Tampermonkey)。创建用户脚本后,您必须重新加载页面。如果控制台已打开,请关闭并重新打开控制台。这些步骤将始终有效。
<top frame> 更改为Tampermonkey 也不起作用 - 它显示GM_x is not defined。
unsafeWindow。显然 Tampermonkey 现在在页面的上下文中运行,而不是在扩展中运行