Giter VIP home page Giter VIP logo

Comments (10)

stirlingTR avatar stirlingTR commented on August 11, 2024 2

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.

skepticfx avatar skepticfx commented on August 11, 2024 2

I see. Thanks @BrightSchema.

from wshook.

stirlingTR avatar stirlingTR commented on August 11, 2024 1

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.

stirlingTR avatar stirlingTR commented on August 11, 2024

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.

skepticfx avatar skepticfx commented on August 11, 2024

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?

image

from wshook.

stirlingTR avatar stirlingTR commented on August 11, 2024

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.

skepticfx avatar skepticfx commented on August 11, 2024

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.

skepticfx avatar skepticfx commented on August 11, 2024

Also, what is your use case here? :)

from wshook.

stirlingTR avatar stirlingTR commented on August 11, 2024

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.

skepticfx avatar skepticfx commented on August 11, 2024

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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.