postMessage: the target origin does not match the recipient window
Your script sends a message to a frame with a target origin, but the page in the frame has another origin. The browser drops the message and writes this warning.
- Chrome
- Edge
- Firefox
- Safari
Updated
Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://example.com') does not match the recipient window's origin ('https://www.example.com').
The message never arrives. Chrome writes a warning, not an error.
Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://example.com') does not match the recipient window's origin ('https://www.example.com').
The message never arrives.
Failed to execute ‘postMessage’ on ‘DOMWindow’: The target origin provided (‘https://example.com’) does not match the recipient window’s origin (‘https://www.example.com’).
The message never arrives.
Unable to post message to https://example.com. Recipient has origin https://www.example.com.
On this page
What it means
Why it happens
Check the page
See the headers the page sends now
Fix it if you own the site
iframe.addEventListener("load", () => {
iframe.contentWindow.postMessage({ type: "hello" }, "https://www.example.com");
});Do not use "*" as the target origin for private data. Any page that loads in the frame would get it.
If you do not own the site
- Tell the owner the right origin
Send them the origin of your page, with the scheme and any port.
- Check the frame URL
Load the final URL of the page, after its redirects, in your iframe.