TampermonKey脚本不使用WebSocket在Web应用程序上启动
我广泛使用GM/TM脚本,除非在一个站点上,否则它们可以毫无失败:一种松弛风格的企业聊天工具,最重要。该页面加载,打开Websocket,然后获取聊天窗格内容并将其填充。
作为测试,我使用了最基本的逻辑来将消息打印到控制台。该脚本适用于整个域,显示为活动性,但没有发出错误或日志。
// ==UserScript==
// @name mattermost
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://*.cloud.mattermost.com/*
// @grant none
// ==/UserScript==
console.log("test")
我尝试过的方法:
- 使用WaitforKeyemements使用各种
@run-at
参数 - ,通常在加载动态内容的站点上
- 添加超时,然后启动
window> window.onload.onload
和unsafewindow.onload
命令在页面加载到整体工作中后直接发给控制台,并且可以随意操纵DOM。关于Websockets,我在这里是否缺少一些警告?
I use GM/TM scripts extensively and they work without fail except on one site: a Slack-style enterprise chat tool, Mattermost. The page loads, opens a websocket, then fetches the chat pane content and populates it.
As a test, I've used the most basic logic to just print a message to the console. The script applies to the entire domain and is shown as active, but no errors or logs are emitted.
// ==UserScript==
// @name mattermost
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://*.cloud.mattermost.com/*
// @grant none
// ==/UserScript==
console.log("test")
Approaches I have tried:
- Using various
@run-at
parameters - Using waitForKeyElements, which usually works on sites loading in dynamic content
- Adding a timeout before firing
- Various invocations of
window.onload
andunsafewindow.onload
Commands issued directly to the console after the page has loaded in its entirety work, and the DOM can be manipulated at will. Is there some caveat I am missing here when it comes to websockets?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经测试了您的“代码”,其中最重要的实例位于我们的公司服务器上。调试信息毫不费力地出现。
正如您所说,您的脚本被标记为活动,不同的匹配模式不应有所作为。
I have tested your "code" with a mattermost instance located on our company server. And the debug message showed up without a hassle.
As you said your script was marked as active the different match patterns shouldn't make a difference.