-
Notifications
You must be signed in to change notification settings - Fork 572
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Web SDK sending info via searchParams (#1427)
* Web SDK sending info via searchParams * rename checkCrossOriginOpenerPolicyCompatibility * checkCrossOriginOpenerPolicy returns policy * sdk-info.ts * yarn prebuild * remove LIB prefix * comments * dont format yml * getter return undefined * error handling + pathname * test
- Loading branch information
1 parent
d06584e
commit 8386209
Showing
17 changed files
with
144 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const VERSION = '4.1.0'; | ||
export const NAME = '@coinbase/wallet-sdk'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/wallet-sdk/src/util/checkCrossOriginOpenerPolicy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const COOP_ERROR_MESSAGE = `Coinbase Wallet SDK requires the Cross-Origin-Opener-Policy header to not be set to 'same-origin'. This is to ensure that the SDK can communicate with the Coinbase Smart Wallet app. | ||
Please see https://www.smartwallet.dev/guides/tips/popup-tips#cross-origin-opener-policy for more information.`; | ||
|
||
/** | ||
* Creates a checker for the Cross-Origin-Opener-Policy (COOP). | ||
* | ||
* @returns An object with methods to get and check the Cross-Origin-Opener-Policy. | ||
* | ||
* @method getCrossOriginOpenerPolicy | ||
* Retrieves current Cross-Origin-Opener-Policy. | ||
* @throws Will throw an error if the policy has not been checked yet. | ||
* | ||
* @method checkCrossOriginOpenerPolicy | ||
* Checks the Cross-Origin-Opener-Policy of the current environment. | ||
* If in a non-browser environment, sets the policy to 'non-browser-env'. | ||
* If in a browser environment, fetches the policy from the current origin. | ||
* Logs an error if the policy is 'same-origin'. | ||
*/ | ||
const createCoopChecker = () => { | ||
let crossOriginOpenerPolicy: string | undefined; | ||
|
||
return { | ||
getCrossOriginOpenerPolicy: () => { | ||
if (crossOriginOpenerPolicy === undefined) { | ||
return 'undefined'; | ||
} | ||
|
||
return crossOriginOpenerPolicy; | ||
}, | ||
checkCrossOriginOpenerPolicy: async () => { | ||
if (typeof window === 'undefined') { | ||
// Non-browser environment | ||
crossOriginOpenerPolicy = 'non-browser-env'; | ||
return; | ||
} | ||
|
||
try { | ||
const url = `${window.location.origin}${window.location.pathname}`; | ||
const response = await fetch(url, { | ||
method: 'HEAD', | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error(`HTTP error! status: ${response.status}`); | ||
} | ||
|
||
const result = response.headers.get('Cross-Origin-Opener-Policy'); | ||
crossOriginOpenerPolicy = result ?? 'null'; | ||
|
||
if (crossOriginOpenerPolicy === 'same-origin') { | ||
console.error(COOP_ERROR_MESSAGE); | ||
} | ||
} catch (error) { | ||
console.error('Error checking Cross-Origin-Opener-Policy:', (error as Error).message); | ||
crossOriginOpenerPolicy = 'error'; | ||
} | ||
}, | ||
}; | ||
}; | ||
|
||
export const { checkCrossOriginOpenerPolicy, getCrossOriginOpenerPolicy } = createCoopChecker(); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.