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

Massive errorcount when having another application using postMessage #17

Open
Mai-Lapyst opened this issue Oct 13, 2022 · 6 comments
Open
Assignees

Comments

@Mai-Lapyst
Copy link

The core library relies on the message event to (it seems) exchange the token from the worker to the application.

But when having another application/library running (i.e. Angular dev tools) that uses the postMessage/message ecessivly, this leads to many errors in the log.

The related code seems to be this:

handle = (e: MessageEvent) => {
console.log(`message received from ${e.origin} with data: ${e.data.token}`);
if (new URL(e.origin).host != this.widgetLink.host) {
console.error(
`expected message from ${this.widgetLink.host} but received message from ${e.origin}. Aborting.`
);
return;
}
this.updateState(e.data.token);
};

Maybe the library should send some sort of identification in the message? I.e: { type: 'mcaptcha', token: xxx }, so the code can check for the type and ignore any other messages?

@realaravinth realaravinth self-assigned this Oct 13, 2022
@realaravinth
Copy link
Member

Thanks for the report and solid idea!

@realaravinth
Copy link
Member

TODO

  1. Define message namespaces (ex: token.pow.mcaptcha.org)
  2. Update sedToParent in server to use namespaces
  3. Update glue to use namespaces

Thoughts?

@Mai-Lapyst
Copy link
Author

Mai-Lapyst commented Oct 13, 2022

You mean that the message then looks like this { "token.pos.mcaptcha.org": "xxx" } right? Seems fine by me.

@realaravinth
Copy link
Member

Yes, but slightly different:

{
    "type": "token.pow.mcaptcha.org",
    "body": {
        "token": "xxx"
    }
}

@Mai-Lapyst
Copy link
Author

I see; this would work too.

@sudoskys
Copy link

sudoskys commented May 8, 2024

I also encountered a lot of errors when applying mCaptcha in vue. In the Vite dev server.

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

3 participants