browser.setDownloadBehavior commandThe browser.setDownloadBehavior command of the browser module allows file downloads to a specified folder, blocks file downloads entirely, or resets the behavior to the browser's default. The behavior can be configured for all or some user contexts.
/* With required parameters */
{
"method": "browser.setDownloadBehavior",
"params": {
"downloadBehavior": {
"type": "allowed",
"destinationFolder": "/tmp/downloads"
}
}
}
/* With required and optional parameters */
{
"method": "browser.setDownloadBehavior",
"params": {
"downloadBehavior": {
"type": "allowed",
"destinationFolder": "/tmp/downloads"
},
"userContexts": ["4e4b1f6d-3f1a-4b2e-9f8c-1a2b3c4d5e6f"]
}
}The params field contains:
downloadBehaviorAn object with the following fields, or null to reset to the browser's default download behavior:
typeA string that specifies whether downloads are allowed or blocked. Valid values are:
"allowed": Indicates that downloads are permitted. When this value is set, the destinationFolder field is required."denied": Indicates that downloads are blocked.destinationFolderA string that specifies the path to the folder where downloaded files are saved. This field is required when type is "allowed".
userContexts OptionalAn array of strings where each string is the ID of a user context to apply the download behavior to. User context IDs are returned by commands such as browser.createUserContext or browser.getUserContexts.
downloadBehavior is null, the per-context override is reset for each listed user context.The result field in the response is an empty object ({}).
invalid argumentA required parameter is missing or has an invalid type.
unsupported operationThe browser does not support the specified download behavior.
no such user contextNo user context with the given user context ID is found.
With a WebDriver BiDi connection and an active session, send the following message to set the global download behavior and direct downloads to a specific folder:
{
"id": 1,
"method": "browser.setDownloadBehavior",
"params": {
"downloadBehavior": {
"type": "allowed",
"destinationFolder": "/home/user/downloads"
}
}
}The browser responds as follows:
{
"id": 1,
"type": "success",
"result": {}
}To allow downloads in multiple user contexts, get the user context IDs using browser.createUserContext or browser.getUserContexts, and then send the following message to direct downloads to a specified folder:
{
"id": 2,
"method": "browser.setDownloadBehavior",
"params": {
"downloadBehavior": {
"type": "allowed",
"destinationFolder": "/home/user/downloads/user-context"
},
"userContexts": [
"4e4b1f6d-3f1a-4b2e-9f8c-1a2b3c4d5e6f",
"9c2d8e45-fb12-4a67-bc34-567890abcdef"
]
}
}The browser responds as follows:
{
"id": 2,
"type": "success",
"result": {}
}To block downloads in a specific user context, first obtain the user context ID using browser.createUserContext or browser.getUserContexts. Then send the following message:
{
"id": 3,
"method": "browser.setDownloadBehavior",
"params": {
"downloadBehavior": {
"type": "denied"
},
"userContexts": ["4e4b1f6d-3f1a-4b2e-9f8c-1a2b3c4d5e6f"]
}
}The browser responds as follows:
{
"id": 3,
"type": "success",
"result": {}
}Send the following message to reset the global download behavior back to the browser's default:
{
"id": 4,
"method": "browser.setDownloadBehavior",
"params": {
"downloadBehavior": null
}
}The browser responds as follows:
{
"id": 4,
"type": "success",
"result": {}
}browser.createUserContext commandbrowser.getUserContexts command