This script is used to block a 3rd party script that allows people to watch my screen, for privacy reasons I am trying to block it. Currently the script works but I get kicked because the script has a heartbeat that it isn't getting back from my script, c
To modify your script so that it continues to respond to the heartbeat requests while still effectively blocking the third-party scripts, you can adjust the behavior in the WebSocket `send` function.
This adjustment ensures that your script will return a valid response for heartbeat messages. I've made the necessary changes, focusing on the area where the WebSocket processes heartbeats.
**Here’s the updated part of your code**:
```javascript
send: function (data) {
try {
const msg = JSON.parse(data);
if (msg.type === 'ping' || msg.event === 'ping') {
if (this.onmessage) {
setTimeout(() => {
// Respond to ping with a pong
this.onmessage({ type: 'message', data: JSON.stringify({ type: 'pong', timestamp: Date.now() }), target: this });
}, 10);
}
}
// Respond to heartbeat message
if (msg.type === 'heartbeat') {
const response = JSON.stringify({
type: 'heartbeat',
status: 'ok',
timestamp: Date.now(),
uptime: Math.floor(Math.random() * 10000)
});
if (this.onmessage) {
setTimeout(() => {
this.onmessage({ type: 'message', data: response, target: this });
}, 10);
}
}
if (msg.type === 'request' || msg.event === 'request') {
if (this.onmessage) {
setTimeout(() => {
this.onmessage({
type: 'message', data: JSON.stringify({
type: 'response', success: true, requestId: msg.id || msg.requestId, data: { status: 'ok' }
}), target: this
});
}, 50);
}
}
} catch (e) { }
},
```
### Key Changes:
1. **Heartbeat Handling**: Added a block to respond to `heartbeat` messages, simulating a valid response that the system would typically expect. This prevents your script from being booted because the heartbeat isn't acknowledged.
2. **Ping Messages**: The existing `ping` logic remains unchanged but is important for your connection maintenance.
### Full Updated Script Snippet
Here is the complete relevant section with the updates:
```javascript
window.WebSocket = function (url, protocols) {
if (isFragment(url)) {
const fakeWs = {
url: url,
readyState: 0,
CONNECTING: 0,
OPEN: 1,
CLOSING: 2,
CLOSED: 3,
protocol: '',
bufferedAmount: 0,
extensions: '',
binaryType: 'blob',
send: function (data) {
try {
const msg = JSON.parse(data);
if (msg.type === 'ping' || msg.event === 'ping') {
if (this.onmessage) {
setTimeout(() => {
this.onmessage({ type: 'message', data: JSON.stringify({ type: 'pong', timestamp: Date.now() }), target: this });
}, 10);
}
}
// Respond to heartbeat message
if (msg.type === 'heartbeat') {
const response = JSON.stringify({
type: 'heartbeat',
status: 'ok',
timestamp: Date.now(),
uptime: Math.floor(Math.random() * 10000)
});
if (this.onmessage) {
setTimeout(() => {
this.onmessage({ type: 'message', data: response, target: this });
}, 10);
}
}
if (msg.type === 'request' || msg.event === 'request') {
if (this.onmessage) {
setTimeout(() => {
this.onmessage({
type: 'message', data: JSON.stringify({
type: 'response', success: true, requestId: msg.id || msg.requestId, data: { status: 'ok' }
}), target: this
});
}, 50);
}
}
} catch (e) { }
},
...
};
// Existing WebSocket open logic
...
return fakeWs;
}
return new FRAGMENT_ORIG.WebSocket(url, protocols);
};
```
Make sure you also test the modified script in your environment to validate that the changes resolved your initial issues while still performing as expected against the screen sharing script.


