For discussing the development and usage of Checkout UI extensions, post-purchase extensions, web pixels, Customer Accounts UI extensions, and POS UI extensions
Hi,
I have a scenario where a javascript (injected using scriptTags)
this script does some calculation & gets a result variable ( const a ="foo" )
I want this script to send a `postmessage` to my extension worker.
Inside my extension, i'm listening for the message,
Checkout.tsx
useEffect(() => { seld.addEventListener("message", (event: { data: string }) => { const data = JSON.parse(event.data) !!data && applyMetaFieldChange({ type: "updateCartMetafield", metafield: { key: "foo-key", namespace: "my-extension-namesapce", type: "single_line_text_field", value: data, }, }).then((result) => { console.log("metafield set in the cart", result); }); }); }, [applyMetaFieldChange]);
when i try to send to postmessage like following in the console window from `top`window..
window.postMessage(JSON.stringify({"foo-key": "abcd"}), "https://extensions.shopifycdn.com") // to the specific target origin
I get the following error
Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://extensions.shopifycdn.com') does not match the recipient window's origin ('https://quickstart-9bac1fe7.myshopify.com').
Solved! Go to the solution
This is an accepted solution.
Hi Manishgowardipe
Checkout Extensibility does not support DOM manipulation or use of custom JavaScript, which may be why you're not able to send to postmessage as expected.
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
This is an accepted solution.
Hi Manishgowardipe
Checkout Extensibility does not support DOM manipulation or use of custom JavaScript, which may be why you're not able to send to postmessage as expected.
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog