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 · API · all subjects

navigation & history

10 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 indexing system

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

NavigationHistory.goToIndex() navigation

Use navigationHistory.goToIndex(index) to navigate to a specific entry in the browsing history by its index position. For example, goToIndex(4) navigates to the 5th entry.

NavigationHistory available methods

The NavigationHistory API provides the following methods: canGoBack(), goBack(), canGoForward(), goForward(), getAllEntries(), goToIndex(index), canGoToOffset(offset), goToOffset(offset), getActiveIndex(), and restore({ index, entries }). Each navigation entry has title and url properties.

NavigationHistory accessed via WebContents

NavigationHistory is stored per WebContents instance. Access it using the webContents.navigationHistory readonly instance property. For a BrowserWindow, this is accessed as mainWindow.webContents.navigationHistory.

NavigationHistory.canGoToOffset() and goToOffset()

Use navigationHistory.canGoToOffset(offset) to check if navigation by offset is possible, and navigationHistory.goToOffset(offset) to navigate by offset from the current position. For example, goToOffset(2) moves forward 2 entries.

NavigationHistory.restore() for history restoration

Call navigationHistory.restore({ index, entries }) to restore a webContents navigation history and position. This method restores both the history entries and the current position in the history stack, allowing goBack() and goForward() to function correctly. This is useful for implementing features like 'undo close tab'.

NavigationHistory back/forward navigation example

To implement back and forward navigation, check canGoBack() or canGoForward() before calling goBack() or goForward(). Example: if (navigationHistory.canGoBack()) { navigationHistory.goBack() }

NavigationHistory getAllEntries() and restore() example

Use navigationHistory.getAllEntries() to retrieve all history entries, each with title and url properties. To restore history to another window: const entries = firstWindow.webContents.navigationHistory.getAllEntries(); const index = firstWindow.webContents.navigationHistory.getActiveIndex(); const secondWindow = new BrowserWindow(); await secondWindow.webContents.navigationHistory.restore({ index, entries })

NavigationHistory.getActiveIndex()

Use navigationHistory.getActiveIndex() to retrieve the current position index in the navigation history stack.

Limit or disable navigation

If your app has no need to navigate or only needs to navigate to known pages, limit navigation to that known scope, disallowing any other kinds of navigation. Use the 'will-navigate' event handler and call event.preventDefault() to disable navigation, or validate the URL using Node's URL parser and an allowlist. Do not use simple string comparisons like startsWith() as they can be fooled.

Give your agent this brain