Skip to content

Commit

Permalink
Try to get the top-most parent.
Browse files Browse the repository at this point in the history
  • Loading branch information
VarunBarad committed Dec 20, 2024
1 parent b8e95de commit 9fc9407
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions sim/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ namespace pxsim.unity {

//% blockId=helloUnity block="helloUnity"
export function helloUnity() {
if (!window.parent) {
let topLevelParent = undefined;
while (window.parent !== topLevelParent) {
topLevelParent = window.parent;
}
if (!topLevelParent) {
console.log('MakeCode: Parent not found');
} else {
console.log(`MakeCode: Parent found. It is: ${window.parent.document.title}`);
window.parent.postMessage({
console.log(`MakeCode: Parent found. It is: ${topLevelParent.document.title}`);
topLevelParent.postMessage({
codeCommand: 'SEND_MIXPANEL_EVENT',
codeData: {
eventName: "BtnClickBrowserVideoPlayerClose",
Expand Down

0 comments on commit 9fc9407

Please sign in to comment.