asticode / go-astilectron

Build cross platform GUI apps with GO and HTML/JS/CSS (powered by Electron)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

require is not defined when injecting ipc interop on window intialization

joshLong145 opened this issue · comments

commented

Currently on the latest version, after a window is created, there is always an observed error of require is undefined which has been observed to come from injected JS context upon window initialization. no combination of option flagging has been observed to fix the issue. this has been tested with go 1.18 and go 1.17

Which platform are you testing on?

commented

Which platform are you testing on?

I am testing with latest version and version 1.18 of go using version 19 of electron. i have also tried numerous electron versions with the same result.

commented

Which platform are you testing on?

I am testing with latest version and version 1.18 of go using version 19 of electron. i have also tried numerous electron versions with the same result.

my operating system is MacOs cpu arch is arm64 (M1)

Did you try with the demo, the example or custom code?

commented

Did you try with the demo, the example or custom code?

I did not test the example. I was testing with a simple index.html with embedded javascript.

Can you reproduce the problem with the example ?

commented

Can you reproduce the problem with the example ?

I can try, i am curious if there is any required implementations within the client web contents that i am missing. I could be missing something but I am unsure as to why the options for node integration are not being respected as if i load the js defined as a string as a preload it does work as expected. but since those options are not exposed to go I feel there arent many options for devs to resolve this.

Thing is I'm not reproducing the problem either in the example or in the demo therefore I'm trying to find where the problem could be coming from. Since you're testing on a different machine than mine, I would like to eliminate the hypothesis that there are specific problems on arm64 (specifically Mac M1) machines. If both the example and the demo work fine on your machine, could you share a snippet of your code so that I see if there are any problems either with astilectron or with the way you're using it ?

commented

Thing is I'm not reproducing the problem either in the example or in the demo therefore I'm trying to find where the problem could be coming from. Since you're testing on a different machine than mine, I would like to eliminate the hypothesis that there are specific problems on arm64 (specifically Mac M1) machines. If both the example and the demo work fine on your machine, could you share a snippet of your code so that I see if there are any problems either with astilectron or with the way you're using it ?

I can share the test bench I was creating. from what i can tell it seems to be an issue with WebPreference option nodeIntegration not being set. it seems the go struct that implements these options does not allow for configuring it which makes sense with the way the project is written as it needs to have commonJS and NodeJS api's available. however it doesnt seem like the flag is being respected as this has been a non default option since Electron version 5 or so. I have tested with a variety of Electron releases and they all give the same issue. If this is not reproducible on your end. do you know if your wrappers require any special boilerplate in the renderer to support node runtime binding correctly?

Sharing the test bench you created would help 👍

nodeIntegration is always set to true in JS in astilectron. Which version of astilectron is it using by the way ?

commented

I was targeting 0.29.0 and also tried a few version back with no successful outcome. We have decided to pivot our strategy to another design which no longer requires an electron binding layer in go. However, I am still curious from a high level if simply defining a static directory with a single index.html as the loaded content for a window should work out of the box. In the examples i see various helper files with this project's namespace for both .css and .js and wondering if they are required in someway. However, to my understanding this error is entirely due to NodeJS interoping through the chromium instance running within electron.

Defining a static directory with a single index.html is perfectly fine, and in most cases is the best solution.