I'm struggling with that one.
The goal is:
I plan to build a chrome extension, that would allow me to visualize an application's traces inside chrome://Tracing.
The extension should :
- receive a json file from some source
- open a new tab on url "chrome://tracing".
- load the json file in this tab
I fail to achieve the thirs step
The goal is not:
- to capture trace from my extension. The extension is not what is generating traces. The traces were generated elsewhere, I'm just trying to visualize them
- to capture traces from something else. The traces were generated in the past, and stored in a database. There's nothing left to plug on.
The question
Is there a way for a Chrome extension to ask or force a tab that loaded the url "chrome://tracing" to load a json file ?
What I tried
Inject javascript into the new tab
Obviously, my first attempt was to insert javascript into the new tab page. I managed to do it on any other page, using things like :
chrome.tabs.onUpdated.addListener
document.createElement
appendChild
Like it is proposed here
I achieved to inject scripts on a tab with urml "https://google.com" for instance. But as soon as I target the url : "chrome://Tracing" injection fails with a cryptic error message in the devTool's console.
I eventually figured out, it's not possible to inject code into chrome extensions. Or maybe it is in a very hacky way if I trust this.
Send messages to the new tab
I hoped that some way, this feature was already planned inside chrome://tracing. So I red the javascript content of tracing.js, in order to find any message I could send to it to ask him to load my file.
But tracing.js is about 80k lines long (beautified), which means that if this message listener exists, I probably missed it.
Use url parameters
With the same amount of optimism, I tried to find any url parameter that would ask the new tab to load this file. But it already was looking like a desperate solution.
Extending DevTools
I assumed that maybe I had different permissions from a DevTools extension than from a regular extension. But the results were the very same. Either I failed to do it properly or my assumption was false.
Working around
Finally I show a message to user, with the path of the file and I ask him to manually click on the "load" button and choose his file.
This is not a good way to do.
What I didn't try
Making my own page that embed tracing.js
I just figure out, my approach may be wrong and I should try to make my own page, instead of trying to use chrome://Tracing.
A quick search show me that there is documentation on embedding catapult's trace-viewer, that I cannot post here due to my low reputation.