Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does this check if the renderer part is being executed in a regular browser? #3

Closed
michaeljota opened this issue Sep 26, 2016 · 3 comments

Comments

@michaeljota
Copy link

I have not try this, but I'm already using this one is-electron-renderer.

However, this have the issue that does not distinguish between renderer process and a browser process, properly webpacked. See this

I would like to know if this support this kind of distinction.

Thanks! :).

@delvedor
Copy link
Owner

delvedor commented Sep 26, 2016

Just to be clear, you have one codebase that works in a standard browser and inside electron, right?

If so, at the moment electron-is can define only if you are in the main/renderer process and not in a standard browser, this because is an electron library ;)

I don't think can be useful implement this function because is an edge case.
What I can suggest you is to create a function to test the presence of the window object.
For example:

function isStandardBrowser () {
  try {
    return !!window
  } catch (e) {
    return false
  }
}
// then
if (is.renderer() || isStandardBrowser()) { ... }

This should work.
But pay attention, the process object does not exist in a standard browser, then basically all electron-is will not work correctly.

@michaeljota
Copy link
Author

michaeljota commented Sep 26, 2016

I added previously the process object through webpack. Thanks! I'll try this and comment. 😃..
PS: Yes. I do want to have a common code to run in renderer and in a regular web browser. :)

@michaeljota
Copy link
Author

FYI: (Or anyone that end up here).

I did the is.standardBrowser() and it worked. BUT. This is a big but, like BUT it didn't matter.
I wanted to use it to require Electron only if this was executed in the renderer process. but it does not. So, kind of waste of time.

Thanks you. Maybe you want to warn me, but I did not read well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants