TypeError: Not enough arguments with window.postMessage on IOS

Viewed 925
window.postMessage(JSON.stringify({
    type: 'loggedIn',
    userToken: token,
}));

My problem is from the above code. It gives me TypeError: Not enough arguments on ios devices. Please help me if you experienced this issue.

Thanks

1 Answers

You're not supplying both required arguments. From the MDN documentation:

 targetWindow.postMessage(message, targetOrigin, [transfer]);

Note that targetOrigin is not optional. Specify the target origin of the message, e.g.:

window.postMessage(JSON.stringify({
    type: 'loggedIn',
    userToken: token,
}), window.origin);
Related