Download
A download activity.
import { Download } from '@mobrowser/api';
Example
import { app, Download } from '@mobrowser/api';
const win = app.createWindow()
win.browser.handle(
'startDownload',
async ({ download }: { download: Download }) => {
download.on(
'progressChanged',
(progress) => { console.log(progress.receivedBytes) }
)
return 'prompt'
}
)
win.browser.downloadUrl('https://example.com/file.zip')
Properties
id
readonly id: string;
The identifier of the download.
url
readonly url: string;
The URL of the download.
mimeType
readonly mimeType: string;
The MIME type of the download.
fileName
readonly fileName: string;
The suggested file name of the download.
isInProgress
readonly isInProgress: boolean;
Indicates if the download is in progress.
isFinished
readonly isFinished: boolean;
Indicates if the download is completely finished.
isCanceled
readonly isCanceled: boolean;
Indicates if the download is canceled.
isPaused
readonly isPaused: boolean;
Indicates if the download is paused.
isInterrupted
readonly isInterrupted: boolean;
Indicates if the download is interrupted.
Methods
pause()
pause(): void;
Pauses the download.
resume()
resume(): void;
Resumes the download.
cancel()
cancel(): void;
Cancels the download.
Events
‘finished’
on(event: 'finished', listener: () => void): void;
off(event: 'finished', listener: () => void): void;
Emitted when the download is completely finished.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.browser.handle('startDownload', async ({ download }) => {
download.on('finished', () => {
console.log('Download finished')
})
return 'prompt'
})
win.browser.downloadUrl('https://example.com/file.zip')
‘canceled’
on(event: 'canceled', listener: () => void): void;
off(event: 'canceled', listener: () => void): void;
Emitted when the download is canceled.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.browser.handle('startDownload', async ({ download }) => {
download.on('canceled', () => {
console.log('Download canceled')
})
return 'prompt'
})
win.browser.downloadUrl('https://example.com/file.zip')
‘paused’
on(event: 'paused', listener: () => void): void;
off(event: 'paused', listener: () => void): void;
Emitted when the download is paused.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.browser.handle('startDownload', async ({ download }) => {
download.on('paused', () => {
console.log('Download paused')
})
return 'prompt'
})
win.browser.downloadUrl('https://example.com/file.zip')
‘interrupted’
on(event: 'interrupted', listener: (reason: DownloadInterruptReason) => void): void;
off(event: 'interrupted', listener: (reason: DownloadInterruptReason) => void): void;
Emitted when the download is interrupted.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.browser.handle('startDownload', async ({ download }) => {
download.on('interrupted', (reason: DownloadInterruptReason) => {
console.log('Download interrupted')
})
return 'prompt'
})
win.browser.downloadUrl('https://example.com/file.zip')
‘progressChanged’
on(event: 'progressChanged', listener: (progress: DownloadProgress) => void): void;
off(event: 'progressChanged', listener: (progress: DownloadProgress) => void): void;
Emitted when the download progress changes.
Example
import { app } from '@mobrowser/api';
const win = app.createWindow()
win.browser.handle('startDownload', async ({ download }) => {
download.on('progressChanged', (progress: DownloadProgress) => {
console.log('Download progress: ', progress.percentComplete, '%')
})
return 'prompt'
})
win.browser.downloadUrl('https://example.com/file.zip')