EDIT: waitForFileChooser does not work when using userProfile with 2+ sessionStorage domains
Baker68 opened this issue · 6 comments
In order to reproduce you need to :
- start a new instance of a secret-agent via
new Agent({...options})
- export and save the profile on disk
const profile = await agent.exportUserProfile();
fs.writeFileSync('profile.json', JSON.stringify(profile));
- close the current secret-agent instance
- start a new instance of a secret-agent via
new Agent({...options, userProfile: JSON.parse(fs.readFileSync('profile.json'))})
waitForFileChooser
won't work when loading a userProfile.
If there are any workarounds, could you please post it ? I know it takes time to fix issues. Thanks in advance.
Thanks for logging @Baker68. Do you have a full code snippet you could share? And/or a session database?
(node:98942) UnhandledPromiseRejectionWarning: TimeoutError: Timeout waiting for filechooser
at new Resolvable (/home/baker/Desktop/work/secret-agent/test-project/node_modules/commons/Resolvable.ts:16:18)
at Object.createPromise (/home/baker/Desktop/work/secret-agent/test-project/node_modules/commons/utils.ts:68:10)
at Page.waitOn (/home/baker/Desktop/work/secret-agent/test-project/node_modules/commons/eventUtils.ts:43:21)
at Tab.waitForFileChooser (/home/baker/Desktop/work/secret-agent/test-project/node_modules/core/lib/Tab.ts:559:37)
at CommandRecorder.runCommandFn (/home/baker/Desktop/work/secret-agent/test-project/node_modules/core/lib/CommandRecorder.ts:79:32)
at Tab.CommandRecorder.owner.<computed> [as waitForFileChooser] (/home/baker/Desktop/work/secret-agent/test-project/node_modules/core/lib/CommandRecorder.ts:22:43)
at ConnectionToClient.executeCommand (/home/baker/Desktop/work/secret-agent/test-project/node_modules/core/server/ConnectionToClient.ts:326:31)
at ConnectionToClient.handleRequest (/home/baker/Desktop/work/secret-agent/test-project/node_modules/core/server/ConnectionToClient.ts:70:25)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
------REMOTE CORE---------------------------------
at Function.reviver (/home/baker/Desktop/work/secret-agent/test-project/node_modules/commons/TypeSerializer.ts:208:26)
at JSON.parse (<anonymous>)
at Function.parse (/home/baker/Desktop/work/secret-agent/test-project/node_modules/commons/TypeSerializer.ts:24:17)
at WebSocket.<anonymous> (/home/baker/Desktop/work/secret-agent/test-project/node_modules/client/connections/RemoteConnectionToCore.ts:67:42)
at WebSocket.emit (events.js:400:28)
at WebSocket.emit (domain.js:475:12)
at Receiver.receiverOnMessage (/home/baker/Desktop/work/secret-agent/test-project/node_modules/ws/lib/websocket.js:1047:20)
at Receiver.emit (events.js:400:28)
at Receiver.emit (domain.js:475:12)
at Receiver.dataMessage (/home/baker/Desktop/work/secret-agent/test-project/node_modules/ws/lib/receiver.js:517:14)
------CONNECTION----------------------------------
at new Resolvable (/home/baker/Desktop/work/secret-agent/test-project/node_modules/commons/Resolvable.ts:16:18)
at Object.createPromise (/home/baker/Desktop/work/secret-agent/test-project/node_modules/commons/utils.ts:68:10)
at RemoteConnectionToCore.createPendingResult (/home/baker/Desktop/work/secret-agent/test-project/node_modules/client/connections/ConnectionToCore.ts:357:31)
at RemoteConnectionToCore.internalSendRequestAndWait (/home/baker/Desktop/work/secret-agent/test-project/node_modules/client/connections/ConnectionToCore.ts:263:43)
at RemoteConnectionToCore.sendRequest (/home/baker/Desktop/work/secret-agent/test-project/node_modules/client/connections/ConnectionToCore.ts:164:17)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async CoreCommandQueue.sendRequest (/home/baker/Desktop/work/secret-agent/test-project/node_modules/client/lib/CoreCommandQueue.ts:150:22)
at async Object.cb (/home/baker/Desktop/work/secret-agent/test-project/node_modules/client/lib/CoreCommandQueue.ts:117:16)
at async Queue.next (/home/baker/Desktop/work/secret-agent/test-project/node_modules/commons/Queue.ts:82:19)
------CORE COMMANDS-------------------------------
at Queue.run (/home/baker/Desktop/work/secret-agent/test-project/node_modules/commons/Queue.ts:35:19)
at CoreCommandQueue.run (/home/baker/Desktop/work/secret-agent/test-project/node_modules/client/lib/CoreCommandQueue.ts:114:8)
at CoreTab.waitForFileChooser (/home/baker/Desktop/work/secret-agent/test-project/node_modules/client/lib/CoreTab.ts:119:36)
at Tab.waitForFileChooser (/home/baker/Desktop/work/secret-agent/test-project/node_modules/client/lib/Tab.ts:200:34)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async Promise.all (index 0)
at async uploadFiles (/home/baker/Desktop/work/secret-agent/test-project/src/test-project/helpers/wallPosting.ts:152:25)
at async wallPosting (/home/baker/Desktop/work/secret-agent/test-project/src/test-project/helpers/wallPosting.ts:205:30)
at async /home/baker/Desktop/work/secret-agent/test-project/src/test-project/index.ts:61:3
--------------------------------------------------
------default-session-2---------------------------
------5632de10-ab8f-11ec-af23-2b6bf4a3201e--------
--------------------------------------------------
(Use `node --trace-warnings ...` to show where the warning was created)
(node:98942) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:98942) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
i am currently trying to write an example based on the website that i'm working on.
However, I think that the issue is one of my plugins that uses beforeHttpResponse
. I will post my findings here.
@blakebyrnes this is the full log debug.txt
the code :
const chosenFiles = readFiles(files);
const photoButton = agent.document.querySelector(
selectors.post_attach_file_button
);
await agent.interact({ move: photoButton }); // ads the <input type="file"> to DOM
await agent.click(photoButton);
const fileChooser = await agent.waitForFileChooser();
await fileChooser.chooseFiles(...chosenFiles);
Would you be willing to send me a session database privately? I don't see anything that stands out in these logs. You can reach me on discord or blake at ulixee.org
@blakebyrnes sure, I've joined the discord server
Issue appears to be related to loading a userProfile with more than 1 sessionStorage. Creating multiple session "restoration" tabs seems to break the events for FileInputs.
Needs investigation into what is causing events to not fire when > 1 domain.
const agent = await handler.createAgent({
humanEmulatorId: 'basic',
userProfile: {
cookies: [],
storage: {
'https://domain1.com': {
indexedDB: [],
localStorage: [],
sessionStorage: [['2', '1']],
},
'https://domain2.com': {
indexedDB: [],
localStorage: [],
sessionStorage: [['1', '2']],
},
},
},
});
const file1 = await Fs.promises.readFile(`${__dirname}/filechooser.test.js`);
const file2 = await Fs.promises.readFile(`${__dirname}/filechooser.test.js.map`);
await agent.goto(`${koaServer.baseUrl}/get-upload-multi`);
await agent.waitForPaintingStable();
const input = await agent.document.querySelector('#sourcefiles');
await agent.click(input);
const chooser = await agent.waitForFileChooser(); <-- HANGS