diff --git a/ghostjs-core/src/chrome/index.js b/ghostjs-core/src/chrome/index.js index 25846cd..6db0bf8 100644 --- a/ghostjs-core/src/chrome/index.js +++ b/ghostjs-core/src/chrome/index.js @@ -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) {