diff options
author | Omar Rizwan <omar@omar.website> | 2021-04-22 16:39:15 -0700 |
---|---|---|
committer | Omar Rizwan <omar@omar.website> | 2021-04-22 16:39:15 -0700 |
commit | 158ad14f97646099809484b3fb3c0c61dc7160e9 (patch) | |
tree | 3dad1594a392cd856df4357d1dd27061d2d44caa | |
parent | 4c30d9f9894236ed27e6542b8d7d0a4fa677f2b0 (diff) | |
download | TabFS-158ad14f97646099809484b3fb3c0c61dc7160e9.tar.gz TabFS-158ad14f97646099809484b3fb3c0c61dc7160e9.zip |
extension: fix hot patching of backgroundJS
(to the point where you can log and it shows up; it doesn't seem able
to replace routes yet)
-rw-r--r-- | extension/background.js | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/extension/background.js b/extension/background.js index 6729c68..d58fbb2 100644 --- a/extension/background.js +++ b/extension/background.js @@ -575,12 +575,14 @@ Routes["/runtime/reload"] = { let __backgroundJS; Object.defineProperty(window, 'backgroundJS', { async get() { - __backgroundJS = __backgroundJS || - await window.fetch(chrome.runtime.getURL('background.js')) - .then(r => r.text()); + if (!__backgroundJS) { + __backgroundJS = await window.fetch(chrome.runtime.getURL('background.js')) + .then(r => r.text()); + } return __backgroundJS; }, - set(js) { __backgroundJS = js; } + set(js) { __backgroundJS = js; }, + configurable: true // so we can rerun this on hot reload }); })(); @@ -599,9 +601,9 @@ Routes["/runtime/background.js"] = { }, async ({}, buf) => { window.backgroundJS = buf; } ), - release({fh}) { + async release({fh}) { // Note that we eval on release, not on write. - eval(window.backgroundJS); + eval(await window.backgroundJS); // TODO: would be better if we could call 'super'.release() so // we wouldn't need to involve how Cache works here. routeWithContents.Cache.removeObjectForHandle(fh); @@ -635,7 +637,7 @@ Routes["/runtime/background.js.html"] = routeWithContents(async () => { <head> <style> body { overflow-x: hidden; } - .route { color: blue; background-color: rgb(255, 196, 196); } + .route { background-color: rgb(255, 196, 196); } .line { position: absolute; height: 15px; width: 100%; } .line { transition: height 0.5s cubic-bezier(0.64, 0.08, 0.24, 1), transform 0.5s cubic-bezier(0.64, 0.08, 0.24, 1); } </style> |