asticode/go-astilectron

How to enable debug on popup windows - attempting to alter DOM on popped up window and it fails

Closed this issue · 5 comments

I am trying to popup a window to display an "About" dialog and need to inject some version information into the DOM.

var newwin = window.open("about.html", "About")
var versionString = "foobar";
newwin.focus();
newwin.onload = function() {
    console.log('in onload newwin ' + versionString);
    // I plan to use the commented out innerHTML stmt below, but while debugging I tried 
    // this "simpler" document.write and it doesnt work either.  Suggesting that perhaps the 
    // event isn't firing or some sort of permissions problem is preventing the parent 
    // window from altering the child window's DOM?
    newwin.document.write("Hello, world!");
//  newwin.document.getElementById("version").innerHTML = versionString;
};

Something isn't working (the window is displayed, but there's no evidence that the onload event fired - the DOM is unchanged). I can't find a way to see the console output for the popped up window (control-D creates debug pane on the main windows, but not on this popped up one).

  • is it possible to enable normal Chrome "click right" context menu to open the Inspect Element tools?
  • can popped up windows somehow "inherit" the debug tooling from the parent window?
  • can anyone spot the error in my javascript that's preventing the newWin.document.write("Hello, world!") or newwin.document.getElementById("version").innerHTML = "some value" to work? (the content displayed in the popup definitely has a span with id "version", so it ought to work...
  • or (prob the best option if it's possible): suggest a way that I can send a message back to the application to directly get the variable from the popup rather than relying on the parent window to pass it to the child. I've tried just invoking astrilectron.sendMessage() from the onload and nothing happens...

I wouldn't create the new window using window.open because this is the basic javascript method which doesn't really give you full control.

One solution is to send a message from JS to GO so that GO creates the new window, that way you can play with dev tools directly. You'll then be able to exchange information between windows through GO.

That sounds like the right approach. I could create the NewWindow from the "About" menu OnClick event directly in go. However, I'm using astrilectron-bootstrap and have initialized the main menu via its Run() routine. I don't see any way to get my hands on the Astilelectron object that I'd need to invoke the NewWindow method. (in bootstrap, its just a local variable 'a' at the top of the Run routine). Do I need to invoke astilelectron.New() again from the OnClick or is there an accessor function I've not found that will get me the bootstrap's instance?

(I tried just creating a second window from bootstrap's Run() with Show:false, then Show() it via the OnClick -- that works until you close the window - once closed, it can never be opened again. I've tried to intercept the beforeunload event to just hide it instead of closing it -- but it doesn't seem to prevent the window from being destroyed - can't get it back once closed.

       window.onbeforeunload = (e) => {
           console.log("close (HIDE) about window");
           window.hide();
           e.returnValue = false;
       }

I don't see any way to get my hands on the Astilelectron object that I'd need to invoke the NewWindow method

You can declare an *astilectron.Astilectron variable somewhere and use the OnWait method to initialize it properly:

var a *astilectron.Astilectron

bootstrap.Options{
  OnWait: func(fa *astilectron.Astilectron, _ []*astilectron.Window, _ *astilectron.Menu, _ *astilectron.Tray, _ *astilectron.Menu) error {
    a = fa
  }
}

once closed, it can never be opened again

You can use either the HideOnClose or MinimizeOnClose options here for that exact problem.

Thank you! I looked right past those options in WidowCustomOptions and didn't notice the Astilectron argument in OnWait.