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

Commit d289f6d

Browse files
committed
Update build process to fix loading errors
Accomodate directories of JS files Address obfuscation key in executing callbacks Update to patch 1.0.1 Change-Id: I6780d4190fcc5b24afee7e73d7ac3413cc1820ea
1 parent ecc3001 commit d289f6d

File tree

8 files changed

+36
-13
lines changed

8 files changed

+36
-13
lines changed

angular.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
},
3939
{
4040
"input": "./dist/client-bundle",
41-
"glob": "*.js",
41+
"glob": "**/*.js",
4242
"output": "."
4343
}
4444
],

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@
33
"author": {
44
"name": "Google LLC"
55
},
6-
"version": "1.0.0",
6+
"version": "1.0.1",
77
"private": true,
88
"license": "Apache-2.0",
9+
"engines": {
10+
"node": ">=12.22.2"
11+
},
912
"scripts": {
1013
"ng": "ng",
1114
"start": "ng serve",
1215
"build": "npm run build:client && npm run build:extension",
13-
"build:client": "tsc --project tsconfig.client.json && parcel build dist/client/*.js --dist-dir dist/client-bundle",
16+
"build:client": "tsc --project tsconfig.client.json && parcel build dist/client/**/*.js --dist-dir dist/client-bundle",
1417
"build:extension": "ng build",
18+
"clean": "rm -rf ./.parcel-cache ./dist",
1519
"fix": "ng lint --fix",
1620
"lint": "ng lint",
17-
"package": "cd dist/interactive-canvas-extension && zip bundle.zip * && mv bundle.zip ../../",
21+
"package": "cd dist/interactive-canvas-extension && zip bundle.zip * **/* && mv bundle.zip ../../",
1822
"test": "npm run lint && npm run test:unit",
1923
"test:unit": "tsc --project tsconfig.ava.json && ava dist/tests/**/*.test.js",
2024
"watch": "ng build --watch --configuration development"

src/bootstrap.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
<html>
1515
<head></head>
1616
<body>
17-
<script src="bootstrap.js"></script>
17+
<script src="webpage/bootstrap.js"></script>
1818
</body>
1919
</html>

src/interactive-canvas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface InteractiveCanvas {
2424
getHeaderHeightPx: () => Promise<number>;
2525
setCanvasState: (state: Object) => Promise<void>;
2626
g: {
27-
G: InteractiveCanvasCallbacks;
27+
[key: string]: InteractiveCanvasCallbacks;
2828
};
2929
}
3030

src/manifest.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Interactive Canvas DevTools",
33
"description": "DevTools for Interactive Canvas",
4-
"version": "1.0.0",
4+
"version": "1.0.1",
55
"manifest_version": 3,
66
"permissions": ["storage", "activeTab", "scripting"],
77
"host_permissions": ["<all_urls>"],
@@ -10,12 +10,12 @@
1010
"matches": ["<all_urls>"],
1111
"exclude_matches": ["*://*.google.com/*"],
1212
"run_at": "document_end",
13-
"js": ["content-script.js"],
13+
"js": ["webpage/content-script.js"],
1414
"all_frames": true
1515
}
1616
],
1717
"web_accessible_resources": [{
18-
"resources": ["js-yaml.min.js", "webpage-script.js"],
18+
"resources": ["js-yaml.min.js", "webpage/webpage-script.js"],
1919
"matches": ["<all_urls>"]
2020
}],
2121
"devtools_page": "bootstrap.html"

src/webpage/content-script.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ declare let window: InteractiveCanvasWindow;
2727
/**
2828
* An array of scripts to be loaded into the primary page context.
2929
*/
30-
const scriptsToLoad = ['js-yaml.min.js', 'webpage-script.js'];
30+
const scriptsToLoad = ['js-yaml.min.js', 'webpage/webpage-script.js'];
3131
scriptsToLoad.forEach(script => {
3232
const s = document.createElement('script');
3333
s.src = chrome.runtime.getURL(script);

src/webpage/webpage-script.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,19 +229,38 @@ window.requestAnimationFrame(() => {
229229
addDebuggingMethodsInJsConsole();
230230
});
231231

232+
/**
233+
* Dynamically gets the correct object within the Interactive Canvas
234+
* object that contains callback methods.
235+
* @returns InteractiveCanvasCallbacks object
236+
*/
237+
function getInteractiveCanvasCallbacks() {
238+
// Internally, the callbacks are stored in interactiveCanvas.g.[letter]
239+
// This letter is not static, and may change with each release.
240+
// We need to iterate through each letter to find callbacks.
241+
const callbackObjectKeys = Object.keys(window.interactiveCanvas.g);
242+
for (const key of callbackObjectKeys) {
243+
// Check that this element has an onUpdate function.
244+
if (window.interactiveCanvas.g[key].onUpdate !== undefined) {
245+
return window.interactiveCanvas.g[key];
246+
}
247+
}
248+
throw new Error('Cannot find callbacks in window.interactiveCanvas.g');
249+
}
250+
232251
document.addEventListener('message', (e: Event) => {
233252
const event = e as MessageEvent;
234253
const eventData = event.data;
235254
const {type} = eventData;
236255
switch (type) {
237256
case 'payload': {
238257
const {data} = eventData;
239-
window.interactiveCanvas.g.G.onUpdate(data);
258+
getInteractiveCanvasCallbacks().onUpdate(data);
240259
break;
241260
}
242261
case 'TtsEndpointEvent': {
243262
const {name} = eventData;
244-
window.interactiveCanvas.g.G.onTtsMark(name);
263+
getInteractiveCanvasCallbacks().onTtsMark(name);
245264
break;
246265
}
247266
case 'Ext-ShowHeader': {

tsconfig.client.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"moduleResolution": "node",
1616
"importHelpers": true,
1717
"target": "ES2020",
18-
"module": "CommonJS",
18+
"module": "ES2015",
1919
"esModuleInterop": false,
2020
"lib": [
2121
"es2018",

0 commit comments

Comments
 (0)