Bug 1750290 Comment 0 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

It is possible (though deeply ill-advised) to convince an add-on and a page to cooperate in the creation of a readable stream where the stream is in the addon, and the source is on the page. 

When this is done with JS Streams, it successfully runs. 

When this is done with DOM Streams, it throws "Permission denied to access property "then"" (almost certainly during the promise resolution process).

The test I have right now is not rigged up for tree inclusion, but looks roughly like this: 

The page under test looks like this: 

```html
<html>
    <body id="body">
        <div id="results"></div>
        <script>
            var results = document.getElementById("results");
            function info(m) {
                results.innerHTML += `<p>${m}</p>`
            }

            var source = {
                start(controller) {
                    console.log('Starting')
                    window.enqueue(controller, "h");
                    window.enqueue(controller, "e");
                    console.log("enqueued");
                }
            }
        </script>
    </body>
</html>
```

and the content script applied to this by the addon is 

```JS
var results = document.getElementById("results");
function info(m) {
    results.innerHTML += `<p><b>From AddOn</b>${m}</p>`
}

// Get the source, unwrapped, from the page. 
var source = window.wrappedJSObject.source;

// Export an addon script function to allow the page to enqueue items. 
function enqueue(controller, value) {
    controller.enqueue(value)
}

exportFunction(enqueue, window, { defineAs: 'enqueue' });

// Create our readable stream
var rs = new ReadableStream(source);
var reader = rs.getReader();

var doRead = async () => {
    console.log("reading")
    var read = await reader.read(); // This await complains about the `.then` property. 
    console.log("read")

    info("Read value: " + read.value);
}

setTimeout(doRead, 1);
setTimeout(doRead, 1);
```
It is possible (though deeply ill-advised) to convince an add-on and a page to cooperate in the creation of a readable stream where the stream is in the addon, and the source is on the page. 

When this is done with JS Streams, it successfully runs. 

When this is done with DOM Streams, it throws "Permission denied to access property "then"" (almost certainly during the promise resolution process).

The test I have right now is not rigged up for tree inclusion, but looks roughly like this: 

The page under test looks like this: 

```html
<html>
    <body id="body">
        <div id="results"></div>
        <script>
            var results = document.getElementById("results");
            function info(m) {
                results.innerHTML += `<p>${m}</p>`
            }

            var source = {
                start(controller) {
                    console.log('Starting')
                    // Note this is an exported function from the addon that does the enqueue. 
                    window.enqueue(controller, "h");
                    window.enqueue(controller, "e");
                    console.log("enqueued");
                }
            }
        </script>
    </body>
</html>
```

and the content script applied to this by the addon is 

```JS
var results = document.getElementById("results");
function info(m) {
    results.innerHTML += `<p><b>From AddOn</b>${m}</p>`
}

// Get the source, unwrapped, from the page. 
var source = window.wrappedJSObject.source;

// Export an addon script function to allow the page to enqueue items. 
function enqueue(controller, value) {
    controller.enqueue(value)
}

exportFunction(enqueue, window, { defineAs: 'enqueue' });

// Create our readable stream
var rs = new ReadableStream(source);
var reader = rs.getReader();

var doRead = async () => {
    console.log("reading")
    var read = await reader.read(); // This await complains about the `.then` property. 
    console.log("read")

    info("Read value: " + read.value);
}

setTimeout(doRead, 1);
setTimeout(doRead, 1);
```

Back to Bug 1750290 Comment 0