Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

108
Views
Stop future object properties from being edited

I'm a JS game dev who's been trying to combat tampermonkey scripts for a while now. I came up with a solution for people hooking into WebSockets where I'd cause the WebSocket to throw an error new WebSocket(0); (0 throws an error due to it being a number)

        let output;
        try {
            output = new target(...args);
        } catch(e) {
            let source = e.stack.substring(e.stack.indexOf("("), 1 + e.stack.indexOf(")"));
            e.stack = e.stack.replace(source, "nothing to see here");
            throw e;
        }

this code made the error's stack have all the information I was looking for replaced!

I've been looking at Object.defineProperty, and I was wondering how I could stop an error's stack from being modified before I have access to that specific error. And if anyone has any other ways I could stop a script from being loaded or run, I'd love to hear them!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

One thing you could do is Object.freeze the error before throwing it. This would prevent people from altering the object's contents.

So for example:

try {
  new WebSocket(0);
} catch (wsErr) {
  throw Object.freeze(wsErr);
}

The code catching your error and trying to alter it would fail to be able to alter it. This should work as it will cause the code that was altering the error to throw with the following:

Cannot assign to read only property 'stack' of object '' 

The other thing you'll have to consider is that in your code where you're catching the error, you will not be able to alter its contents either. Typically with errors, that's not a huge deal though. Tampering with errors is one of the only reasons I can think of for modifying the error.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!