question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Electron preload w/ Bytenode encoded renderer

See original GitHub issue

Running into issues using a preload script in Electron with Bytenode encoded renderer files.

Contextisolation is enabled, hence require is not available in index.html in renderer, so the renderer jsc files can’t be decoded there (which is what I did before using preload).

Moved this to my preload script:

contextBridge.exposeInMainWorld(
    'api',
    {
        view: () => {
            const bytenode = require('bytenode');
            return require('./path/to/my.jsc');
        }
    }
);

I can then trigger this via IPC from the renderer:

<script defer>
    window.api.view();
</script>

This does work (I see some of the app’s console logs), but the problem is that the jsc file is now being executed in the context of the preload script and NOT in the browser window, hence all other calls to the preload’s api object (from the app) do NOT work, which is what my app needs.

Any solution for this ?

I also tried using bytenode.runBytecodeFile() and bytenode.runBytecode(), could not get this to work.

Thanks.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:22

github_iconTop GitHub Comments

1reaction
OsamaAbbascommented, May 6, 2021

(1) is there an updated version of this comparison ? is your opinion the same today ?

I’m still leaning towards NW.js. If I have to choose between them I would go with NW.js for sure.

But before taking this decision, I would also study the security vulnerabilities (an example here) in Electron and figure out their counterparts in NW.js and how to deal with them.

(2) have you ever written a blog post about migrating from Electron to NW.js or have you ever have to migrate one to the other ?

I have not. I have no experience with Electron so far other than trying to solve bytenode’s issues.

1reaction
petef19commented, May 5, 2021

@OsamaAbbas

btw, I happened to stumble across your NW.js vs. Electron comparison on hackermoon from 2018 (appreciate the write up and comparison). I know this is off topic here, but since this is closed, maybe I can ask a couple of q’s: 😉

(1) is there an updated version of this comparison ? is your opinion the same today ? (2) have you ever written a blog post about migrating from Electron to NW.js or have you ever have to migrate one to the other ?

Looking into other options again re our latest discussions. Appreciate the feedback and advise shared.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Electron renderer.js listen app.js and preload.js - Stack Overflow
To implement 'Separation of Concerns' and keep hard-coded functions out of the preload.js script, you can refactor your preload.js script so ...
Read more >
Subverting Electron Apps via Insecure Preload
Preloading Insecurity In Your Electron. Preload is a mechanism to execute code before renderer scripts are loaded.
Read more >
Electron preload w/ Bytenode encoded renderer - bytemeta
Running into issues using a preload script in Electron with Bytenode encoded renderer files. Contextisolation is enabled, hence require is not available in ......
Read more >
preload electron的價格和怎麼買, PTT加密貨幣版
preload electron 在Electron preload w/ Bytenode encoded renderer - GitAnswer 的相關結果. Running into issues using a preload script in Electron with ...
Read more >
8.xml - jsDelivr
... https://www.jsdelivr.com/package/npm/@or-change/duck-electron monthly ... www.jsdelivr.com/package/npm/@pangwu86/markdown-it-disable-url-encode monthly ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found