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

Fix/detect in iframe fix #2475

Merged
merged 9 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/twelve-clouds-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@adyen/adyen-web': patch
---

Renaming detectInIframe to the more accurate, but lengthy, detectInIframeInAccessibleDomain.
Now the functionality only considers itself to be running in an iframe _if_ it is possible to access the parent domain and thus be able to redirect the top, parent, window
2 changes: 1 addition & 1 deletion packages/lib/src/components/Redirect/Redirect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Redirect from './Redirect';
import RedirectShopper from './components/RedirectShopper';
import RedirectElement from './Redirect';

jest.mock('../../utils/detectInIframe', () => {
jest.mock('../../utils/detectInIframeInAccessibleDomain', () => {
return jest.fn().mockImplementation(() => {
return true;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, h } from 'preact';
import detectInIframe from '../../../../utils/detectInIframe';
import detectInIframeInAccessibleDomain from '../../../../utils/detectInIframeInAccessibleDomain';

interface RedirectShopperProps {
beforeRedirect: (resolve, reject, url) => Promise<void>;
Expand All @@ -21,7 +21,7 @@ class RedirectShopper extends Component<RedirectShopperProps> {
if (this.postForm) {
this.postForm.submit();
} else {
if (this.props.redirectFromTopWhenInIframe && detectInIframe()) {
if (this.props.redirectFromTopWhenInIframe && detectInIframeInAccessibleDomain()) {
// if in an iframe and the config prop allows it - try to redirect from the top level window
window.top.location.assign?.(this.props.url);
} else {
Expand Down Expand Up @@ -51,7 +51,7 @@ class RedirectShopper extends Component<RedirectShopperProps> {
ref={ref => {
this.postForm = ref;
}}
{...(this.props.redirectFromTopWhenInIframe && detectInIframe() && { target: '_top' })}
{...(this.props.redirectFromTopWhenInIframe && detectInIframeInAccessibleDomain() && { target: '_top' })}
>
{Object.keys(data).map(key => (
<input type="hidden" name={key} key={key} value={data[key]} />
Expand Down
2 changes: 0 additions & 2 deletions packages/lib/src/utils/detectInIframe.ts

This file was deleted.

7 changes: 7 additions & 0 deletions packages/lib/src/utils/detectInIframeInAccessibleDomain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Returns true if the page is being run in an iframe (in a domain we have access to)
sponglord marked this conversation as resolved.
Show resolved Hide resolved
export default () => {
if (window.parent.location instanceof Location) {
sponglord marked this conversation as resolved.
Show resolved Hide resolved
return window.location !== window.parent.location;
}
return false; // we cannot access window.parent.location - so consider us "not to be in an iframe" for the purpose of Redirects
};
Loading