Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions ghostjs-core/src/chrome/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,24 @@ class ChromePageObject {
}
}

async uploadFile (selector, filePath) {
this.getCDP().then(async (client) => {
const { Page, Runtime, DOM } = client
try {
await Page.enable()
await DOM.enable()
await Runtime.enable()

const { objectId } = await Runtime.evaluate({ expression: `document.querySelector(${selector})` })
const node = await DOM.requestNode(objectId)

await DOM.setFileInputFiles({ files: [filePath], nodeId: node })
} catch (err) {
console.error(err)
}
})
}

close () {
this.getCDP().then(async (client) => {
if (this.targetId) {
Expand Down