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

Default to creating agent iframe on widget create #31

Merged
merged 2 commits into from
Jan 24, 2025

Conversation

greenberga
Copy link
Contributor

@greenberga greenberga commented Jan 24, 2025

There are a few things happening in this pull request.

1. No more baseURL on FriendlyCaptchaSDK

Can cause problems in the (rare) event of having widgets with different API endpoints on a single page. Instead, each widget is responsible for "setting up" an apiURL.

2. opts.startAgent, if truthy, can be used to pre-load the agent iframe at SDK-construction.

In that case, it will configure the agent iframe using the endpoint passed as an option to the SDK constructor, falling back to the search algorithm outlined in options.ts, and finally defaulting to the global endpoint.

3. In the default case, the agent iframe is now created upon widget creation

The widget also takes care to add the correct origin to the CommunicationBus. I think the original timeout errors might've been caused by a CommunicationBus configured with the global endpoint in combination with an eu widget. I.e., the problem wasn't that there were two iframes, it's that there was only a global origin in the CommunicationBus, and the EU widget couldn't use it.

Fixes https://github.com/FriendlyCaptcha/friendly-captcha/issues/1889

@greenberga greenberga added the bug Something isn't working label Jan 24, 2025
@greenberga greenberga self-assigned this Jan 24, 2025
@greenberga greenberga requested a review from gzuidhof January 24, 2025 11:24
@greenberga
Copy link
Contributor Author

By the way, this passes all the tests when I run go run main.go autotest except csp. But csp seems to be failing on main too, so I'm not too worried about that.

@@ -222,27 +219,13 @@ export class FriendlyCaptchaSDK {
}
}

private getAPIUrls(apiURL?: string | { agent: string; widget: string }) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to lose this 👍

@greenberga greenberga merged commit 5fca23d into test-sdk-loading-before-widget-tag Jan 24, 2025
2 checks passed
@greenberga greenberga deleted the defer-iframe-loading branch January 24, 2025 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants