mirror of
https://github.com/Heretek-AI/GDevelop.git
synced 2026-07-24 20:05:39 -04:00
5efbaa8c58
* This will allow to detect any bugs or crash in the game engine without relying on manual reports from users on GitHub. Note that exceptions and errors in JavaScript code blocks won't be reported. This can be deactivated in preferences if you prefer not to have GDevelop send these crash reports at all.
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
namespace gdjs {
|
|
const logger = new gdjs.Logger('Debugger client (window message)');
|
|
|
|
/**
|
|
* This debugger client connects to the parent window, exchanging
|
|
* and receiving messages using `postMessage` and the `message` event listener.
|
|
*/
|
|
export class WindowMessageDebuggerClient extends gdjs.AbstractDebuggerClient {
|
|
_opener: Window | null = null;
|
|
|
|
constructor(runtimeGame: RuntimeGame) {
|
|
super(runtimeGame);
|
|
|
|
this._opener = window.opener || null;
|
|
if (!this._opener) {
|
|
logger.info("`window.opener` not existing, the debugger won't work.");
|
|
return;
|
|
}
|
|
|
|
window.addEventListener('message', (event) => {
|
|
const data = event.data;
|
|
this.handleCommand(data);
|
|
});
|
|
}
|
|
|
|
protected _sendMessage(message: string) {
|
|
if (!this._opener) return;
|
|
|
|
try {
|
|
this._opener.postMessage(message, '*');
|
|
} catch (error) {
|
|
this._originalConsole.warn(
|
|
'Error while sending a message to the debugger:',
|
|
error
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
//Register the class to let the engine use it.
|
|
// @ts-ignore
|
|
export const DebuggerClient = WindowMessageDebuggerClient;
|
|
}
|