Comments (4)
We can remove the throw unknown message but, expecting some random page to not throw on an unknown message seems like it would make many pages not work in the debugger. Is there some other way to pass the message? Even worse, the inspector's use of messages might conflict with the page's use of messages in general.
Like any random page might have something like
postMesasge({a: {b: 123}});
onmessage = (e) => {
console.log(e.data.a.b);
}
The page expects it always gets an object with a
. If it doesn't it will throw
You could maybe wrap onmessage
and window.addEventListener
and filter out your messages before they get to the page?
from webgpu-samples.
I think this will wrap onmessage
and addEventListener
const GlobalCtor = globalThis.constructor;
const GlobalPropertyDescriptors = Object.getOwnPropertyDescriptors(globalThis);
const isOurMessage = e => e.data.sig === 'webgpu_inspector';
const listenerToWrapperFn = new WeakMap();
function makeWrapper(listener) {
const wrapper = function(event) {
if (isOurMessage(event)) {
// do something with our message
console.log('got message from us', event.data);
} else {
return listener.call(this, event);
}
};
listenerToWrapperFn.set(listener, wrapper);
return wrapper;
}
Object.defineProperty(globalThis, 'onmessage', {
get() {
const listener = GlobalPropertyDescriptors.onmessage.get.call(this);
return listenerToWrapperFn.get(listener) ?? listener;
},
set(listener) {
GlobalPropertyDescriptors.onmessage.set.call(this, makeWrapper(listener));
}
});
GlobalCtor.prototype.addEventListener = (function(origFn) {
return function(name, listener, ...args) {
listener = name === 'message' ? makeWrapper(listener) : listener;
return origFn.call(this, name, listener, ...args);
}
})(GlobalCtor.prototype.addEventListener);
GlobalCtor.prototype.removeEventListener = (function(origFn) {
return function(name, listener, ...args) {
listener = listenerToWrapperFn.get(listener) ?? listener;
return origFn.call(this, name, listener, ...args);
};
})(GlobalCtor.prototype.removeEventListener);
from webgpu-samples.
Yeah, maybe I need to go back to the drawing board on that one.
from webgpu-samples.
I'll close this issue. I think a CustomEvent is probably the better choice for this rather than message. Thanks for setting me straight.
from webgpu-samples.
Related Issues (20)
- Some samples don't work on Edge 122 with Intel Iris Plus graphics HOT 1
- Link to or embed other known samples HOT 5
- Sample using 3D textures HOT 7
- Set up PR previews
- iframe change followup
- ERROR: GET /worker.js?service [404: does not exist] HOT 2
- Missing redirect HOT 1
- Add a simple search filter
- Add page icon to index.html
- Add social media meta info
- Can't run Hello Triangle sample on Linux HOT 3
- Add light/dark support to samples and menus
- Textures not working in certain samples HOT 4
- Re-add scrolling tabs HOT 1
- ViewSource button appears non-functional on Chrome Version 122.0.6261.112 (Official Build) (arm64) HOT 6
- a-buffer broken in light mode
- Indirect Draw Call Sample HOT 3
- When uploadvideo type is ogv, importExternalTexture report error HOT 4
- The "find" functionality is broken on desktop. Makes it hard to navigate the code. HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webgpu-samples.