benweet / stackedit.js

Add StackEdit to any website
https://benweet.github.io/stackedit.js/
MIT License
1.08k stars 119 forks source link

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('file://') does not match the recipient window's origin ('null'). #8

Closed para2402 closed 6 years ago

para2402 commented 6 years ago

My code is as follows:

<!DOCTYPE html>
<html>
    <head>
        <script src="https://unpkg.com/stackedit-js@1.0.5/docs/lib/stackedit.min.js"></script>
    </head>

    <body>
        <textarea></textarea>

        <script>
            const el = document.querySelector('textarea');
            const stackedit = new Stackedit();

            // Open the iframe
            stackedit.openFile({
                name: 'Filename', // with an optional filename
                content: {
                  text: el.value // and the Markdown content.
                }
            });

            // Listen to StackEdit events and apply the changes to the textarea.
            stackedit.on('fileChange', (file) => {
                el.value = file.content.text;
            });
        </script>
    </body>
</html>

It worked for a while but then the following error started showing up:

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('file://') does not match the recipient window's origin ('null').

It appears in the console as soon as the page loads. It also appears for every key that I type in the markdown section in the editor

benweet commented 6 years ago

It will probably fail with protocol file://. Are you running your site from your hard drive?

para2402 commented 6 years ago

Problem solved. Thanks.