MessageChannel is not defined
See original GitHub issueBasic info:
I am attempting to use Zombie.js (which uses jsdom) to debug Message Channel generation, but it doesn’t seem to be defined. According to the MDN docs, the MessageChannel constructor has support going all the way back to IE10, so it seems strange that it’s not supported here
- Node.js version: 10.10.0
- jsdom version: 13.0.0
Minimal reproduction case
'use strict';
// Let's see if MessageChannel is supported
let html = `
<!DOCTYPE html>
<body>
<h1 id='title'>
Does MessageChannel Exist?
</h1>
<script>
var title = document.getElementById('title');
try {
window.channel = new MessageChannel();
} catch(e) {
console.log('Error caught: ' + e.message)
}
if (window.channel) {
title.innerHTML = 'MessageChannel Exists!';
} else {
title.innerHTML = 'MessageChannel Does not Exist :(';
}
</script>
</body>
</html>
`;
const { JSDOM } = require('jsdom');
const { window } = new JSDOM(html, {runScripts: 'dangerously'});
console.log(window.eval('document.getElementById("title").innerHTML'));
// Expected -> 'MessageChannel Exists!'
// Actual ---> 'MessageChannel Does not Exist :('
Running the above node file should print the string “MessageChannel Exists!” and produce no errors. However, when running using jsdom a “MesssageChannel is not defined” error is thrown, and the console logs “MessageChannel Does not Exist 😦”
How does similar code behave in browsers?
Example of working code in JSFiddle: https://jsfiddle.net/hvLpg6tm/5/
The HTML provided is exactly the same
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:6
Top Results From Across the Web
ReferenceError: MessageChannel is not defined #2984 - GitHub
Basic info: Node.js version: v12.16.1 jsdom version: 16.2.2 Minimal reproduction case const axios = require("axios"); const { JSDOM } ...
Read more >'MessageChannel is undefined' triggered on pages with ...
I'm currently trying to scrape some sites that have recaptcha implemented, but whenever i load the page's source i get this error: (node:15536) ......
Read more >MessageChannel - Web APIs | MDN
The MessageChannel interface of the Channel Messaging API allows us to create a new message channel and send data through it via its...
Read more >lightning web components - MessageChannel not working
Message Channel definition : <?xml version="1.0" encoding="UTF-8"?> <LightningMessageChannel xmlns="http://soap.sforce.com/2006/04/metadata"> ...
Read more >MessageChannel JavaScript and Node.js code examples
setImmediate}catch(c){K=function(a){var b=new MessageChannel;b.port1.onmessage=a;b.port2.postMessage(void 0)}}return K(a)} undefined.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Looks like one could just do this as of Node 10.5.0:
Source: https://nodejs.org/api/worker_threads.html#worker_threads_class_messagechannel
However, one needs to pass Node the
--experimental-worker
flag.If someone adds this, there is one concern that I think needs to be resolved.
jsdom sandboxes timers. I.e.
setTimeout
andsetInterval
don’t hold the Node process hostage if you callwindow.close()
. They’re automatically cancelled.I believe that jsdom should do the same for
MessageChannel
ports, if it were to addwindow.MessageChannel
. Concretely,window.close()
should also close all open ports. Otherwise, the Node process won’t exit.