Skip to content

WebContentsDidNavigateEvent ​

WebContentsDidNavigateEvent represents the web page moving to a new URL.

The did-navigate event of WebContents is this class. It carries the new URL and the HTTP status code.

Inheritance: Event → WebContentsDidNavigateEvent

Constructor ​

WebContentsDidNavigateEvent()

Creates a WebContentsDidNavigateEvent. The runtime creates one itself when it fires the events below; app code can use it to build an event object and fire it with dispatchEvent() to try out a listener.

Instance properties ​

Also inherits the properties of Event; the most commonly used are type and target. The properties below are read-only; assigning to them throws TypeError.

PropertyDescription
url read-onlyThe new URL
httpResponseCode read-onlyThe HTTP status code

These properties live on the prototype, not on the event object itself: Object.keys(event) and { ...event } don't include them, so read them one by one. See Events with fields.

Events that use this class ​

ObjectEvents
WebContentsdid-navigate

It can't be canceled: cancelable is false, and preventDefault() has no effect.

Examples ​

js
const contents = new WebView().webContents;
contents.addEventListener('did-navigate', (e) => {
  console.log(e instanceof WebContentsDidNavigateEvent, e.httpResponseCode, e.url);
});
contents.loadURL('https://example.com');

Effect: once the page loads, prints true 200 https://example.com/. Not verified in the simulator.

Corresponding iOS API ​

There is no corresponding system API. The event name and field names follow the event of the same name on Electron's webContents. The native equivalent is webView:didCommitNavigation:.

See also ​