new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Electron · Tutorial · all subjects

navigation-history

13 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

NavigationHistory API overview

The NavigationHistory class allows you to manage and interact with the browsing history of your Electron application. Navigation history is stored per WebContents instance and can be accessed via the webContents.navigationHistory property.

Access NavigationHistory from WebContents

Navigation history is accessed through the WebContents instance using the navigationHistory property. For example, mainWindow.webContents.navigationHistory provides access to the NavigationHistory instance for that window.

Check and perform forward navigation

Use navigationHistory.canGoForward() to check if forward navigation is available, then call navigationHistory.goForward() to navigate to the next page in history.

Get all history entries

Call navigationHistory.getAllEntries() to retrieve an array of all navigation entries. Each entry contains at least a title and url property.

Navigation history indexing system

Navigation history entries are indexed sequentially. Index 0 represents the earliest visited page, and index N represents the most recent page visited.

Navigate to specific history entry by index

Call navigationHistory.goToIndex(index) to navigate directly to a specific entry in the history. For example, goToIndex(4) navigates to the 5th entry (0-indexed).

Navigate by offset from current position

Use navigationHistory.canGoToOffset(offset) to check if navigation by offset is possible, then call navigationHistory.goToOffset(offset) to navigate forward or backward by a number of entries from the current position.

Restore navigation history

Call navigationHistory.restore({ index, entries }) to restore a WebContents' navigation history and position. This restores both the history entries and the current position in the history stack, allowing goBack() and goForward() to work as expected on the restored history.

Get current position in history

Call navigationHistory.getActiveIndex() to retrieve the current position (index) within the navigation history stack.

Example: Back and forward navigation

const { BrowserWindow } = require('electron') const mainWindow = new BrowserWindow() const { navigationHistory } = mainWindow.webContents // Go back if (navigationHistory.canGoBack()) { navigationHistory.goBack() } // Go forward if (navigationHistory.canGoForward()) { navigationHistory.goForward() }

Example: Display all history entries

const entries = navigationHistory.getAllEntries() entries.forEach((entry) => { console.log(`${entry.title}: ${entry.url}`) })

Example: Navigate to specific entries

// Navigate to the 5th entry in the history, if the index is valid navigationHistory.goToIndex(4) // Navigate to the 2nd entry forward from the current position if (navigationHistory.canGoToOffset(2)) { navigationHistory.goToOffset(2) }

Example: Restore history for undo close tab

const firstWindow = new BrowserWindow() // Later, you want a second window to have the same history and navigation position async function restore () { const entries = firstWindow.webContents.navigationHistory.getAllEntries() const index = firstWindow.webContents.navigationHistory.getActiveIndex() const secondWindow = new BrowserWindow() await secondWindow.webContents.navigationHistory.restore({ index, entries }) }

Give your agent this brain