1

I am facing a problem, SAB(SharedArrayBuffer) does not work in cross-domain environment. Target IFrame's source is on another domain, I added aliases to hosts file(Windows OS). I am sending SAB through postMessage to IFrame, but it simply does not either send or receive. If IFrame's source is something like this: "./frames/frame.html", SAB starts magically work. What can be done to make SAB work in cross-domain?

I am using Google Chrome, in Console window it does not show errors. When using Firefox, it provides this error: Cannot post message containing a shared memory object to a cross-origin window.

Website is hosted using webpack with headers:

Cross-Origin-Opener-Policy : same-origin
Cross-Origin-Embedder-Policy : require-corp
11
  • Are you using TLS? Commented Aug 8, 2022 at 9:18
  • @BrownieInMotion Yes, I also created certificate for all domains and added that certificate to trusted in Windows OS. Commented Aug 8, 2022 at 9:53
  • Have you tried also sending a Cross-Origin-Resource-Policy: cross-origin response header? Commented Aug 8, 2022 at 11:00
  • @sideshowbarker Yes, backend responses with such header Commented Aug 8, 2022 at 12:41
  • 1
    @Kaiido I haven’t looked yet at the relevant spec bits to know what the expected behavior should be per-spec Commented Aug 9, 2022 at 9:43

1 Answer 1

1

If your cross-domain environment consists of subdomains to the same parent domain (e.g. one.domain.com and two.domain.com) or even sub.domain.com and domain.com then this shows precisely which headers you need to set up on each domain: https://stackoverflow.com/a/74923275/7326344

In the iframe's .htaccess (on sub.domain.com) I needed:

Header set Cross-Origin-Embedder-Policy "require-corp"
Header set Cross-Origin-Opener-Policy "same-origin"
Header set Cross-Origin-Resource-Policy "same-site"

In the root document's .htaccess (on domain.com) I needed:

Header set Cross-Origin-Embedder-Policy "require-corp"
Header set Cross-Origin-Opener-Policy "same-origin"
Sign up to request clarification or add additional context in comments.

1 Comment

While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.