#Display the variable from .js to .html in electron

254 messages · Page 1 of 1 (latest)

lapis ice
#

Same as on browser

ancient idol
lapis ice
#

So what you expect then?

#

Complete code?

ancient idol
#

idea

lapis ice
#

If you supposed to use electron you need nodejs/web knowledge

ancient idol
#

trades.js

#

main.js

#

what I`m doing wrong?

lapis ice
#

where is preload file?

ancient idol
lapis ice
#

this is the issue

ancient idol
#

What I need to add?

lapis ice
#

have you seen example from link above?

ancient idol
#

yeah, but I don't understand it

lapis ice
#

what exactly?

ancient idol
#

example different from what I nedd

lapis ice
#

its example

ancient idol
#

added this, still same error

lapis ice
#

have you change your code after that change?

ancient idol
#

I reloaded app

#

how to change it so it will always listen ?

#

or every second

lapis ice
#

this is button click event

ancient idol
#

I understand

#

but how to do always listener ?

lapis ice
#

what always listener means?

#

and for what?

ancient idol
#

to check renderer every second

lapis ice
#

how do you listen before?

ancient idol
#

Im not

lapis ice
#

O_o

#

how familiar you with nodejs/js?

ancient idol
#

noob.

lapis ice
#

how you supposed to use electron then?

golden arrow
#

I think it's another "spoon story", as you would put it

ancient idol
#

thx

#

problem was here btw

lapis ice
#

no

#

its not a problem

ancient idol
#

why the error gone then?

lapis ice
#

you disable security feature

#

sadly

golden arrow
#

:/

ancient idol
#

I did it, but with

      contextIsolation: false,
}```
#

I deleted const { ipcRenderer } = require('electron'); from trades.js file

#

it work but with disabled security feature

#

in main.js

#

trades.js

#

how to do it correctly with enabled security feature ?

#

what I shoud add to preload ?

lapis ice
#

by using preload file

ancient idol
#

what I shoud add to preload ?

lapis ice
#

have you read docs anout preload file?

#

this one?

ancient idol
#

yeah, but I don't understand what I should send from preload file to the main file

lapis ice
#

preload file used to make a bridge

#

between renderer and main

ancient idol
#

ohh

lapis ice
#

with preload you can extends renderer

#

like this one

ancient idol
#

yeah, i m looking at it right now

#

i need some time to understand

ancient idol
#

did like this

#

but it did't work

lapis ice
#

what didnt work?

ancient idol
#

still same errors

lapis ice
#

you cant use require

#

thats why you have preload

ancient idol
#

deleted const { ipcRenderer } = require('electron');

lapis ice
#

yeah

#

correct

#

use api you exposed via preload

ancient idol
#

ohh

#

moved this from trades.js to preload

#

I need use import ?

lapis ice
#

for what?

ancient idol
#

to get variable from preload

lapis ice
#

no

ancient idol
#

so how I need to move api from trades.js to preload ?

lapis ice
#

you cant move it

#

if you move dependency into preload

#

you should work with them in preload

ancient idol
lapis ice
#

do you understand what preload is?

ancient idol
#

yes

#

but I dont understand how to fix these errors

lapis ice
#

do you know what those errors means?

ancient idol
#

no

lapis ice
#

do you know what reference is?

ancient idol
#

yes

lapis ice
#

do you know what value is?

#

or variable

ancient idol
#

this ?

lapis ice
#

there are many things on this image

#

your errors means that varaibles ipcRenderer and require is not defined

#

becase require is not usable in browser/renderer code by default

#

and you cant use require at all

#

if you cant use require electron you cant require ipcRenderer and use it

#

thats why you have preload file

#

where you have require

#

and can use it

#

with ipcRenderer

#

and you have contextBridge to extends renderer code with some api

ancient idol
#

so it mean my preload file is not correct ?

lapis ice
#

you renderer code is not correct

#

becase you still trying to use old code

ancient idol
#

don't get it

#

what old code?

lapis ice
#

you have old code with ipcRenderer and require in index.html and trades.js files

ancient idol
#

I cant use ipcRenderer.send in trades.js ?

lapis ice
#

no

ancient idol
#

can't or can ?

lapis ice
#

you cant

#

but you can use api you create with contextBridge

ancient idol
#

but firstly I need to edit my preload file correctly

#

I need ipcRenderer.send in preload ?

#

and sent variable from trades.js to preload via preload apis ?

lapis ice
#

You already have ipcRenderer.send in preload

ancient idol
#

is it correct ?

lapis ice
#

Yes

#

Exposing ipc channel is not recommended

ancient idol
#

okay, but what I need to do in html ?

lapis ice
#

Same thing?

ancient idol
ancient idol
golden arrow
#

don't use require in the renderer

ancient idol
#

i dont

lapis ice
#

What data is?

golden arrow
ancient idol
ancient idol
#

these are the only require I use in trades.js

lapis ice
#

Remove it

ancient idol
#

I can't, then code wouldn't work

lapis ice
#

Its doesn't work because if require as well

#

If you wanted to work with it move your code into preload

ancient idol
#

but then preload file would be so big

#

can I somehow move it to preload and then use it in trades from preload ?

lapis ice
#

you can require trades in preload

ancient idol
#

how?

lapis ice
#

with require()

ancient idol
lapis ice
#

do you know what require() is?

ancient idol
#

I think

#

it is like import

lapis ice
#

what import is?

ancient idol
#

get something from somewhere

lapis ice
#

so

#

you can get something with require

ancient idol
#

whole trades.js file ?

lapis ice
#

whole file

ancient idol
#

but I will still use require in trades.js

lapis ice
#

if you require trades in preload

#

require is not an issue

ancient idol
#

added const trades = require('./trades.js'); to preload, but still have errors

golden arrow
#

One key security feature in Chromium is that processes can be executed within a sandbox. The sandbox limits the harm that malicious code can cause by limiting access to most system resources — sandboxed processes can only freely use CPU cycles and memory. In order to perform operations requiring additional privilege, sandboxed processes use dedi...

lapis ice
#

remove trades.js from html file

#

at first

#

2nd

#

you dont have data value to use it

ancient idol
#

I think I don't have data because of this

lapis ice
#

no

ancient idol
lapis ice
#

require ipcRenderer

#

from electron

#

and use it instead of electronAPI

ancient idol
#

also use ipcRenderer in html ?

lapis ice
#

no

ancient idol
#

but what I need to do with html ?

#

only 1 error left

lapis ice
#

=/

ancient idol
#

what use instead ?

golden arrow
#

have you followed IPC tutorial?

lapis ice
#

used for what?

ancient idol
lapis ice
#

do you have variable to display?

ancient idol
#

topValues from trades

lapis ice
#

how it supposed to be in html?

#

what topValues is?

ancient idol
#

before I used ipcRender to display data from main.js

lapis ice
#

you used ipcRenderer to get it

ancient idol
#

okay, how to get it without iprRenderer ?

lapis ice
#

i dont know?

#

there are many ways to get it

#

its your code

#

not mine

ancient idol
lapis ice
#

from where?

#

why do you need ipcRenderer?

#

if you dont have anything in main?

ancient idol
lapis ice
#

do you know what this code do?

ancient idol
#

send data

lapis ice
#

from where?

ancient idol
#

from trades.js

lapis ice
#

and send data to?

ancient idol
lapis ice
#

so what you expect me to answer then?

#

if you cant tell me what do you want?

ancient idol
lapis ice
#

how do you get topValues in trades?

ancient idol
#

from binance api and webSocket

lapis ice
#

show me the code

ancient idol
lapis ice
#

you can use this code in trades.js

ancient idol
lapis ice
#

why do you add script into html file?

ancient idol
#

now 2 errors

lapis ice
#

data is not defined

#

you need to fix it

ancient idol
#

cant I just use only getElementById somehow ?

lapis ice
#

you can

ancient idol
#

I tried it before but it didn't work

#

bruh

#

it work

#

oh

#

it didn't work because of preload

#

It needed to require trades.js

#

all these days I only had to add 1 line of code despair

#

@lapis ice Thank you

lapis ice
#

nope

#

not only 1 line of code

ancient idol
#

wait, why this happened?

lapis ice
#

becase it cant load source map

ancient idol
lapis ice
#

becase it doesnt exists

ancient idol
#

what doesnt exists?

lapis ice
#

source maps

ancient idol
#

so I can ignore it ?

ancient idol
lapis ice
#

because you have 246 msg post to explain you what to do

#

for basic stuff

ancient idol
lapis ice
#

do you understand what you did?

ancient idol
#

yes

#

I was looking for help

lapis ice
#

you was looking for a teacher

#

if you supposed to use electron you should know nodejs and web