xpl / ololog

A better console.log for the log-driven debugging junkies
https://www.npmjs.com/package/ololog
The Unlicense
215 stars 8 forks source link

xhr request fails in iframe #20

Open hlolli opened 4 years ago

hlolli commented 4 years ago

Thanks for the best logging library out there!

One glitch I bumped into, when calling log.info from inside iframe, an iframe which I instantiate as BlobURL.

The call would be here

            try {
                if (isBrowser) {

                    let xhr = new XMLHttpRequest ()

                        xhr.open ('GET', path, false /* SYNCHRONOUS XHR FTW :) */)
                        xhr.send (null)

                    this.text = xhr.responseText

                } else {

The error in Chrome

6cb0327a-6bb3-4ae6-87cf-91d6c71c5e80:5667 GET blob:http://localhost:3000/4c010b36-0716-4494-8acf-ddb045159385/ net::ERR_FILE_NOT_FOUND

The iframe I create btw like this

    const iFrameHtml = [
      `<!doctype html>`,
      `<html lang="en">`,
      `<head>`,
      `</head>`,
      `<body>`,
      `<script type="text/javascript" src="${ScriptProcessorNodeWorker()}"></script>`,
      `</body>`,
    ].join('\n');

    const iFrameBlob = new Blob([iFrameHtml], { type: 'text/html' });
    const iFrame = document.createElement('iframe');
    iFrame.src = URL.createObjectURL(iFrameBlob);
    iFrame.sandbox.add('allow-scripts', 'allow-same-origin');
    document.body.appendChild(iFrame);
xpl commented 4 years ago

I'm not sure yet what exactly is happening, but as a quick workaround you can try disabling location tags, so it won't try to fetch the page source:

log = ololog.configure ({ locate: false })