Files
Nicolas Chevobbe 4c0129c06c Bug 1767724 - [devtools Fix browser_webconsole_console_logging_workers_api.js intermittent. r=devtools-reviewers,bomsy.
The test was calling `logFromWorker` twice, which means we were getting some duplicated
messages which could mess with some assertions. The second call wasn't even needed
so we can simply remove it.

Also, because the test was using a data url worker, in the test we were matching some
assertions not on the message body, but on the message location, which means we
weren't properly checking what we wanted, and possibly were triggering some actions
to early/late.

This patch migrates the worker content to an existing worker file that we then
use in the support file, so we don't match on the message location anymore.

Differential Revision: https://phabricator.services.mozilla.com/D246412
2025-04-24 07:52:03 +00:00

39 lines
1.1 KiB
JavaScript

"use strict";
console.log("initial-message-from-worker", { foo: "bar" }, globalThis);
self.addEventListener("message", function onMessage(event) {
const { type, message } = event.data;
// Override Date.prototype.getTime and RegExp.toString to make sure those are not
// called when logging to the console (see Bug 1892638)
const date = new Date(2024, 0, 1);
date.getTime = () => {
return 42;
};
// eslint-disable-next-line no-extend-native
Date.prototype.getTime = date.getTime;
const regexp = /foo/m;
regexp.toString = () => {
return "24";
};
switch (type) {
case "log":
console.log(message);
break;
case "error":
throw new Error(message);
case "log-objects":
console.log("log-from-worker", message, globalThis);
console.log(Symbol("logged-symbol-from-worker"));
console.log(["array-item", 42, { key: "value" }]);
console.log("sab-from-worker", event.data.sab);
/* Check if page functions can be called by console previewers */
console.log("date-from-worker", date);
console.log("regexp-from-worker", regexp, /not-overloaded/g);
break;
}
});