Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My production stopped out of nowhere with error Uncaught TypeError: Cannot assign to read only property 'copy' of object '[object Object]' #79

Open
hiagodotme opened this issue Feb 7, 2024 · 2 comments

Comments

@hiagodotme
Copy link

Today one of my published projects presented the error Uncaught TypeError: Cannot assign to read only property 'copy' of object '[object Object]'.

We didn't update anything so we started investigating and the error is returned by the script "https://hcaptcha.com/1/api.js?render=explicit" loaded by ng-hcaptcha.

Other projects of mine, using the same version, continue to work correctly. What could be causing this? My environment runs under Angular 15.

api.js?render=explicit:3 Uncaught TypeError: Cannot assign to read only property 'copy' of object '[object Object]'
    at Object.<anonymous> (api.js?render=explicit:3:262458)
    at 29.base64-js (api.js?render=explicit:3:263818)
    at o (api.js?render=explicit:3:221092)
    at api.js?render=explicit:3:221144
    at 2.buffer (api.js?render=explicit:3:221758)
    at o (api.js?render=explicit:3:221092)
    at api.js?render=explicit:3:221144
    at 8../buffer-global (api.js?render=explicit:3:225354)
    at o (api.js?render=explicit:3:221092)
    at api.js?render=explicit:3:221144
@hiagodotme
Copy link
Author

After a lot of struggle, I found the cause of the problem.

In my Angular project, there is a file src/prototypes.ts this file was created by a developer two years ago to facilitate copying Angular objects without reference.

The content is exactly this:

export const prototypes = (): void => {
     Object.defineProperty(Object.prototype, 'copy', {
         value: function (): any {
             const obj = JSON.parse(JSON.stringify(this));
             return obj;
         },
     });
};

Luckily for me, only one place in the application used this, so I refactored and deleted the contents of prototypes.ts.

I believe that HCaptcha made some recent update that conflicted with this code in the core of my Angular project.

@hiagodotme
Copy link
Author

I'll leave it open, maybe other people might be going through this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant