asticode / go-astilectron

Build cross platform GUI apps with GO and HTML/JS/CSS (powered by Electron)
MIT License
4.9k stars 344 forks source link

BrowserView with go-astilectron #320

Open Rukenshia opened 3 years ago

Rukenshia commented 3 years ago

Hi there,

I wanted to try and use go-astilectron to create an application that loads another website and adds additional functionality for it - it's a website that allows downloading mods for a game. Now, when loading the website directly in a NewWindow, I can see some JavaScript errors which seem to stem from JS files being loaded out of order (it loads fine in a <webview>). From what info I could gather, it looks like I should be using a <webview> tag or a BrowserView. <webview> is discouraged, so I tried looking up how to create a BrowserView with this package, but was unable to find anything. Is there a way of creating a BrowserView with go-astilectron or another workaround?

Cheers,

asticode commented 3 years ago

Mmm I find it weird that JS files would be loaded out of order using a Window and not a BrowserView... 🤔 Could you share JS errors here?

Unfortunately right now BrowserView is not handled by this lib.

Rukenshia commented 3 years ago

Thank you so much for your quick reply, really appreciate it!

Here's the code I used:

package main

import (
    "log"
    "os"

    "github.com/asticode/go-astikit"
    "github.com/asticode/go-astilectron"
)

func main() {
    // Initialize astilectron
    a, _ := astilectron.New(log.New(os.Stderr, "", 0), astilectron.Options{
        AppName:            "Flightsim.to desktop",
        AppIconDefaultPath: "./icon.png",
    })
    defer a.Close()

    // Start astilectron
    a.Start()

    var w, _ = a.NewWindow("https://flightsim.to", &astilectron.WindowOptions{
        Center: astikit.BoolPtr(true),
    })
    w.Create()
    w.OpenDevTools()

    // Blocking pattern
    a.Wait()
}

It throws a bunch of errors about jQuery not being available:

image

If I change the URL to google.com and navigate to the website, I can see that a jQuery asset gets loaded, but after the bundle.js file:

image

asticode commented 3 years ago

OK I get it. Check out this comment.

Do you have control on the website you're loading?

Rukenshia commented 3 years ago

Thanks for the context!

Sadly I don't control the website - I'm currently using a webview and it works fine so far, but I'm not sure if that will work long term for me without a BrowserView judging from their notes on webview. Feel free to close the issue if BrowserView support won't be possible :)

Thanks a lot for your help again!