Last active
April 18, 2024 20:26
-
-
Save iwoodruff/7744574bd96a26526bfb30327d3934ad to your computer and use it in GitHub Desktop.
Revisions
-
iwoodruff revised this gist
Apr 18, 2024 . 1 changed file with 2 additions and 2 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ const API_KEY = '' // your app's apiKey, provided to your app during config, also accessible via window.shopify.config.apiKey interface FrameList extends Window { @@ -25,7 +25,7 @@ function findAppFrameSafely(frameName: string) { const legacyFrameName_doNotUse = 'app-iframe'; const futureProofFrameName = `frame:${API_KEY}/main`; const appFrame = findAppFrameSafely(legacyFrameName_doNotUse) || findAppFrameSafely(futureProofFrameName); -
iwoodruff revised this gist
Apr 18, 2024 . 1 changed file with 2 additions and 2 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 charactersOriginal file line number Diff line number Diff line change @@ -24,8 +24,8 @@ function findAppFrameSafely(frameName: string) { } const legacyFrameName_doNotUse = 'app-iframe'; const futureProofFrameName = `frame:${APP_API_CLIENT_ID}/main`; const appFrame = findAppFrameSafely(legacyFrameName_doNotUse) || findAppFrameSafely(futureProofFrameName); -
iwoodruff created this gist
Apr 16, 2024 .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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ const APP_API_CLIENT_ID = '' // your app's api_client_id interface FrameList extends Window { [index: number]: Window; } function findAppFrameSafely(frameName: string) { if (window.parent) { const frames = window.parent.frames as FrameList; for (let i = 0; i < frames.length; i++) { const frame = frames[i]; try { // referencing the name prop of a cross-origin frame will throw when there are multiple frames with the same name if (frame.name === frameName) { return frame; } } catch (_) { // noOp } } } } const legacyFrameName_doNotUse = 'app-iframe'; // this will break & should be removed once we switch to the new pattern const futureProofFrameName = `frame:${APP_API_CLIENT_ID}/main`; // once all 1p apps stop relying on name="app-iframe", we will change the app iframe name to this pattern const appFrame = findAppFrameSafely(legacyFrameName_doNotUse) || findAppFrameSafely(futureProofFrameName); // continue doing whatever you were doing with the app's main frame appFrame?.postMessage({}, window.location.origin);