Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Commit c14a66e

Browse files
committed
Add console methods to simplify triggering callbacks
Bug: 193062584 Bug: 193666575 Change-Id: I8e08aec3c2313f9965413d5a7eff3c5b2038bf1d
1 parent c5159ac commit c14a66e

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/interactive-canvas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export interface InteractiveCanvas {
3232
* Types for Interactive Canvas callbacks.
3333
* @see https://developers.google.com/assistant/interactivecanvas/reference#interactivecanvascallbacks
3434
*/
35-
interface InteractiveCanvasCallbacks {
35+
export interface InteractiveCanvasCallbacks {
3636
onUpdate: (data: Object[]) => Promise<void> | undefined;
3737
onTtsMark: (markName: string) => void;
3838
}

src/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {InteractiveCanvas} from './interactive-canvas';
17+
import {
18+
InteractiveCanvas,
19+
InteractiveCanvasCallbacks,
20+
} from './interactive-canvas';
1821

1922
/**
2023
* A representation of Interactive Canvas events that appear in the History tab
@@ -85,6 +88,7 @@ export interface InteractiveCanvasWindow extends Window {
8588
*/
8689
logoSrcData: string;
8790
};
91+
interactiveCanvasDebug: InteractiveCanvasCallbacks;
8892
/**
8993
* JSYaml is a 3P library that converts YAML to JSON.
9094
* @see https://www.npmjs.com/package/js-yaml

src/webpage-script.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,36 @@ function addUnsupportedApiWarnings() {
490490
addPropertyWarning('webkitSpeechRecognition', window);
491491
}
492492

493+
/**
494+
* Add methods as `window.interactiveCanvasDebug` to trigger callbacks
495+
* programmatically from the DevTools console.
496+
*/
497+
function addDebuggingMethodsInJsConsole() {
498+
window.interactiveCanvasDebug = {
499+
onUpdate: (data: Object[]) => {
500+
const msgData = {
501+
data: {
502+
type: 'payload',
503+
requestId: 'requestId',
504+
data,
505+
},
506+
};
507+
document.dispatchEvent(new MessageEvent('message', msgData));
508+
return undefined;
509+
},
510+
onTtsMark: (markName: string) => {
511+
const msgData = {
512+
data: {
513+
type: 'payload',
514+
requestId: 'requestId',
515+
data: markName,
516+
},
517+
};
518+
document.dispatchEvent(new MessageEvent('message', msgData));
519+
},
520+
};
521+
}
522+
493523
window.requestAnimationFrame(() => {
494524
const hasInteractiveCanvas = window.interactiveCanvas !== undefined;
495525

@@ -528,6 +558,7 @@ window.requestAnimationFrame(() => {
528558

529559
window.interactiveCanvasProcessSdk = processSdk;
530560
addUnsupportedApiWarnings();
561+
addDebuggingMethodsInJsConsole();
531562
});
532563

533564
document.addEventListener('message', (e: Event) => {

0 commit comments

Comments
 (0)