Description
First of all, thanks for this awesome tool! 👏
I am wondering if it's possible to programmatically load local trace files with https://chromedevtools.github.io/timeline-viewer/
I've been experimenting with puppeteer to automate the drag-and-drop interaction but I can't get a file to load. I noticed that on the initial dragover event, the UI changes from #dropbox
to the timeline widget. I also figured out how to retrieve the drop target element from
timeline-viewer/docs/dev_tools.js
Line 154 in f3e7ce0
dragenter
, dragover
, drop
event on window.Timeline.TimelinePanel.instance()._dropTarget._element
nothing happens.
With puppeteer, I am doing the following:
const fileInputIdentifier = 'some-unique-identifier';
await page.evaluate(() => {
document.querySelector('#dropbox').dispatchEvent(new Event('dragover'));
});
await page.waitFor(2500);
await page.evaluate(
id => {
document.body.appendChild(
Object.assign(document.createElement('input'), {
id,
type: 'file',
onchange: async e => {
['dragenter', 'dragover', 'drop'].forEach(event => {
window.Timeline.TimelinePanel.instance()._dropTarget._element.dispatchEvent(
Object.assign(new Event(event), {
dataTransfer: { files: e.target.files }
})
);
});
}
})
);
},
fileInputIdentifier
);
const fileInput = await page.$(`#${fileInputIdentifier}`);
await fileInput.uploadFile(filePath);
await fileInput.evaluate(upload =>
upload.dispatchEvent(new Event('change', { bubbles: true }))
);
It appears as if the drop event is registered, but the file is not loaded due to the following error:
Uncaught TypeError: Cannot convert undefined or null to object
at Function.from (<anonymous>)
at UI.DropTarget._hasMatchingType (shell.js:1724)
at UI.DropTarget._onDragEnter (shell.js:1722)
at HTMLInputElement.onchange (VM49 __puppeteer_evaluation_script__:11)
at VM46 __puppeteer_evaluation_script__:2
Maybe my approach is overkill or simply not feasible. Any idea? Thanks a lot :)