{"id":13798029,"url":"https://github.com/jprichardson/is-electron-renderer","last_synced_at":"2025-04-09T22:18:49.238Z","repository":{"id":34592258,"uuid":"38539559","full_name":"jprichardson/is-electron-renderer","owner":"jprichardson","description":"Check if code is running in Electron renderer process","archived":false,"fork":false,"pushed_at":"2019-04-25T17:44:36.000Z","size":7,"stargazers_count":78,"open_issues_count":1,"forks_count":12,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-09T22:18:44.985Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jprichardson.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-04T16:06:54.000Z","updated_at":"2024-06-27T02:13:19.000Z","dependencies_parsed_at":"2022-09-13T05:41:23.626Z","dependency_job_id":null,"html_url":"https://github.com/jprichardson/is-electron-renderer","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jprichardson%2Fis-electron-renderer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jprichardson%2Fis-electron-renderer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jprichardson%2Fis-electron-renderer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jprichardson%2Fis-electron-renderer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jprichardson","download_url":"https://codeload.github.com/jprichardson/is-electron-renderer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248119285,"owners_count":21050755,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T00:00:38.051Z","updated_at":"2025-04-09T22:18:49.216Z","avatar_url":"https://github.com/jprichardson.png","language":"JavaScript","funding_links":[],"categories":["Library","Tools"],"sub_categories":["Check/Detect","For Electron"],"readme":"is-electron-renderer\n====================\n\nCheck if code is running in Electron `renderer` process.\n\nWhy?\n----\n\nElectron code can run in either the `main` process or\nthe `renderer` process. This is the same as asking if\nthe code is running in a web page with access to the\nDOM or not. Read more here: https://github.com/atom/electron/blob/master/docs/tutorial/quick-start.md\n\n### Use Cases:\n\n- Creating a single module that acts differently whether it's running in `main` or `renderer`.\n- Logging utility. One process (`main`) would be responsible for writing to log files, while\nrenderers would send log data to the `main`. Would allow your code to have one `log` method.\n- Testing. Your test code may behave differently if the DOM is available.\n- Normalize `console.log` behavior. `console.log` behavior is weird in `renderer`, this can easily be fixed.\n\nInstall\n-------\n\n    npm i --save is-electron-renderer\n\n\nUsage\n-----\n\nYou'll notice that when using `console.log` in Electron that in the `renderer` process\noutputs some weird log level garbage to `stderr` before your actual console message.\nYou can normalize this behavior:\n\n**console-hook.js**:\n\n```js\n// clean up Electron output\nfunction hook () {\n  var isRenderer = require('is-electron-renderer')\n  var pre = '(' + (isRenderer ? 'RENDERER' : 'MAIN') + ') '\n  console.log = function (msg) {\n    process.stdout.write(pre + msg + '\\n')\n  }\n}\n\nmodule.exports = {\n  hook: hook\n}\n```\n\n**index.js**:\n\n```js\nrequire('./console-hook').hook()\nconsole.log('hello')\n```\n\noutput (main):\n\n    (MAIN) hello\n\noutput (renderer):\n\n    (RENDERER) hello\n\n\nAPI\n---\n\n```js\nvar isRenderer = require('is-electron-renderer')\nconsole.log(isRenderer)\n// =\u003e (BOOLEAN)\n```\n\nLicense\n-------\n\nMIT\n\nCopyright 2015 [JP Richardson](https://github.com/jprichardson)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjprichardson%2Fis-electron-renderer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjprichardson%2Fis-electron-renderer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjprichardson%2Fis-electron-renderer/lists"}