generated from chibat/chrome-extension-typescript-starter
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Current state: - I'm able to send messages to the sandbox. - The sandbox is able to render the Handlebars content. - *The sandbox cannot send messages back to the caller!* I don't understand why this isn't working given that I'm following the doc here: https://developer.chrome.com/docs/extensions/mv2/sandboxingEval/; when I attempt to send a message to the source of my message, the source is the sandboxed frame. This is obviously not going to work given that I want to send the message to the parent frame instead (& unforch, you can't access `window.parent` either). Definitely perplexed and I've already spent enough time on this today.
- Loading branch information
1 parent
216a760
commit 5bd2480
Showing
13 changed files
with
236 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Obsidian Handlebars Sandbox</title> | ||
<script src="js/vendor.js"></script> | ||
</head> | ||
|
||
<body class="options"> | ||
<script src="js/handlebars.js"></script> | ||
<div id="debug"> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import Handlebars from "handlebars"; | ||
import { | ||
SandboxRequest, | ||
SandboxRenderResponse, | ||
SandboxRenderRequest, | ||
} from "./types"; | ||
|
||
const render = (request: SandboxRenderRequest): SandboxRenderResponse => { | ||
const compiled = Handlebars.compile(request.template); | ||
|
||
return { | ||
success: true, | ||
request, | ||
rendered: compiled(request.context), | ||
}; | ||
}; | ||
|
||
function handleEvent(evt: MessageEvent<SandboxRequest>): void { | ||
if (evt.origin === "null") { | ||
console.log("Received event from self :-(", evt); | ||
return; | ||
} | ||
console.log("Parent: ", window.parent); | ||
console.log("Received event: ", evt); | ||
|
||
const command = evt.data.command; | ||
const postMessage = (evt.source as WindowProxy).postMessage; | ||
console.log("Received event (Src): ", evt.source); | ||
|
||
const debug = document.getElementById("debug"); | ||
if (debug) { | ||
debug.innerHTML = JSON.stringify(evt.data); | ||
} | ||
|
||
try { | ||
switch (command) { | ||
case "render": | ||
postMessage(render(evt.data), "*"); | ||
break; | ||
default: | ||
return; | ||
throw new Error(`Unexpected command: ${command}`); | ||
} | ||
} catch (e) { | ||
console.error(e); | ||
postMessage( | ||
{ | ||
success: false, | ||
request: evt.data, | ||
message: (e as Error).message, | ||
}, | ||
"*" | ||
); | ||
} | ||
} | ||
|
||
window.addEventListener("message", handleEvent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.