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

webcontents: files & urls

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

win.previewFile(path[, displayName]) method (macOS)

Uses Quick Look to preview a file at a given path. Takes path (string - the absolute path to the file to preview, important as Quick Look uses the file name and file extension to determine content type) and optionally displayName (string - the name of the file to display on the Quick Look modal view, purely visual and doesn't affect content type, defaults to path).

win.closeFilePreview() method (macOS)

Closes the currently open Quick Look panel.

win.loadURL(url[, options])

Loads the URL in the window. The url parameter is a string (can be a remote address like http:// or a path to a local HTML file using file:// protocol). The options parameter is optional and an Object with: httpReferrer (string or Referrer, optional), userAgent (string, optional), extraHeaders (string, optional, extra headers separated by newline), postData (UploadRawData or UploadFile array, optional), and baseURLForDataURL (string, optional, base URL with trailing path separator for files to be loaded by data URL, needed only if url is a data URL and needs to load other files). Returns Promise<void> which resolves when the page has finished loading (see did-finish-load event) and rejects if the page fails to load (see did-fail-load event). A noop rejection handler is already attached to avoid unhandled rejection errors. If the existing page has a beforeUnload handler, did-fail-load will be called unless will-prevent-unload is handled. Same as webContents.loadURL(url[, options]). To ensure that file URLs are properly formatted, it is recommended to use Node's url.format() method.

win.loadURL() with file:// protocol example

const { BrowserWindow } = require('electron') const win = new BrowserWindow() const url = require('node:url').format({ protocol: 'file', slashes: true, pathname: require('node:path').join(__dirname, 'index.html') }) win.loadURL(url)

win.loadURL() with POST data example

const { BrowserWindow } = require('electron') const win = new BrowserWindow() win.loadURL('http://localhost:8000/post', { postData: [{ type: 'rawData', bytes: Buffer.from('hello=world') }], extraHeaders: 'Content-Type: application/x-www-form-urlencoded' })

win.loadFile(filePath[, options])

Loads a local HTML file in the window. The filePath parameter is a string that should be a path to an HTML file relative to the root of your application. The options parameter is optional and an Object with: query (Record<string, string>, optional, passed to url.format()), search (string, optional, passed to url.format()), and hash (string, optional, passed to url.format()). Returns Promise<void> which resolves when the page has finished loading (see did-finish-load event) and rejects if the page fails to load (see did-fail-load event). Same as webContents.loadFile.

Give your agent this brain

webcontents: files & urls — Electron · API