Comments (10)
I'm using tampermonkey for the user script, so just in the script's header.
This is the working code.
// ==UserScript==
// @name wsHook Test
// @version 1
// @grant none
// @require https://cdn.rawgit.com/skepticfx/wshook/master/wsHook.js
// @run-at document-start
// @match https://play.idle.land/*
// ==/UserScript==
wsHook.before = function (data, url, wsObject) {
return data;
}
wsHook.after = function (data, url, wsObject) {
return data;
}
Also worth noting, if you change //@grant none
it will sandbox the code and prevent wsHook from working.
No worries anyways, simple fix and it looks very clean in the end.
from wshook.
I see. Thanks @BrightSchema.
from wshook.
Well, I've found the issue. The wshook was created after the websocket had already been made.
Adding // @run-at document-start
and requiring the raw file fixed it.
from wshook.
I've changed my code a bit to make sure I was okay on my end.
// make websocket hook
let websockethook = document.createElement('script');
websockethook.setAttribute('type', 'text/javascript');
document.body.appendChild(websockethook);
websockethook.onload = () => {
wsHook.before = function (data, url) {
console.log("Sending message to " + url + " : " + data);
return data;
}
}
websockethook.setAttribute('src', 'https://cdn.rawgit.com/skepticfx/wshook/master/wsHook.js');
In the console wsHook.before.toString()
returns the updated function, however it does not ever trigger.
from wshook.
It seems to be working fine for me when the page uses a simple websocket like https://websocket.org/echo.html
Maybe your page uses a different WebSocket implementation?
from wshook.
Well, that's unfortunate, just tested in chrome and firefox (not with echo but the site I'm looking at) same way you did with no luck.
The site is open sourced on github but I'm assuming because of angular I can't find a way to access the websocket from a script.
If you have any ideas I'd love to hear them, otherwise feel free to close the issue. Thanks
from wshook.
can you point me to the website or the open source code? Would love to make it work. I want to support socket.io when I get a chance.
from wshook.
Also, what is your use case here? :)
from wshook.
Website is https://idle.land with the source code at https://github.com/IdleLands/IdleLands/
It's a game that sends playerdata through the websocket, and I'm trying to automate player actions using the websocket hook. I've been talking to the dev about it, and he is fine with any attempts I make for automation as long as it doesn't overload the server :)
So far it looks as though it is using socketcluster-client for creating the websocket. From what I've seen socketcluster-client uses the normal WebSocket constructor, but I'm still learning this stuff as I go.
And thank you for helping :)
from wshook.
Sorry I missed this. Am glad it works now. Where are you adding those @run-at document-start
at?
from wshook.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wshook.