![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
electron-as-browser2
Advanced tools
A node module to help build browser like windows in electron.
npm i electron-as-browser2
const BrowserLikeWindow = require('electron-as-browser2');
let browser;
browser = new BrowserLikeWindow({
controlPanel: 'renderer/you-control-interface.html',
startPage: 'https://page-to-load-once-open',
blankTitle: 'New tab',
debug: true // will open controlPanel's devtools
});
// Trigger on new tab created
browser.on('new-tab', ({ webContents }) => {
// Customize webContents if your like
});
browser.on('closed', () => {
// Make it garbage collected
browser = null;
});
To make the control interface works, there are two steps:
For react users, there is a custom hook useConnect
to help you setup ipc channels.
const useConnect = require('electron-as-browser2/useConnect');
const ControlPanel = () => {
const { tabs, tabIDs, activeID } = useConnect();
return (
<div>Use tabs' information to render your control panel</div>
);
}
For non-react users, you have to setup ipc channels yourself, there are three steps:
ipcRenderer.send('control-ready')
on dom readyipcRenderer.on('tabs-update', (e, tabs) => { // tabs updated })
ipcRenderer.on('active-update', (e, activeID) => { // Active tab's id updated })
Don't forget to removeListener
on ipcRenderer
once control panel unmounted.
Once setup ipc channels, you'll get all your control panel needed informations:
tabs
an object contains all the opened tab's informationstabIDs
array of opened tab's idsactiveID
current active tab's idConstruct and style your control interface as your like.
Then you can send actions to control the browser view, the actions can require from electron-as-browser/control
:
import {
sendEnterURL, // sendEnterURL(url) to load url
sendChangeURL, // sendChangeURL(url) on addressbar input change
sendGoBack,
sendGoForward,
sendReload,
sendStop,
sendNewTab, // sendNewTab([url])
sendSwitchTab, // sendSwitchTab(toID)
sendCloseTab // sendCloseTab(id)
} from 'electron-as-browser/control';
See example for a full control interface implementation.
FAQs
Make electron like browser easy and flexible.
The npm package electron-as-browser2 receives a total of 5 weekly downloads. As such, electron-as-browser2 popularity was classified as not popular.
We found that electron-as-browser2 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.