Yes, you can do this via chrome.devtools.inspectedWindow API ()
You can track
a) Content of all available fragments
b) When a new fragment and its contents are added
c) When Snippet is updated with new content \ modified.
As always to enable debugging, etc. You must enable the experimental developer flags .
You can take the following code as a reference, and you can renew it according to your requirement.
manifest.json
You must add
"devtools_page": "devtools.html",
to manifest.json file
Manifest.json example
{ "name":"Snippets Demo", "description":"This demonstrates How to get content from Snippets API", "devtools_page":"devtools.html", "manifest_version":2, "version":"2" }
devtools.html
Add devtools.js to avoid inline scripts
Devtools.html example
<html> <head> <script src="devtools.js"></script> </head> <body> </body> </html>
devtools.js
Add related code for
a) chrome.devtools.inspectedWindow.getResources
b) chrome.devtools.inspectedWindow.onResourceAdded.addListener
c) chrome.devtools.inspectedWindow.onResourceContentCommitted.addListener ()
Devtools.js example
//Fetching all available resources and filtering using name of script snippet added chrome.devtools.inspectedWindow.getResources(function (resources){ // This function returns array of resources available in the current window for(i=0;i<resources.length;i++){ // Matching with current snippet URL if(resources[i].url == "Script snippet #1"){ resources[i].getContent(function (content,encoding){ alert("encoding is " + encoding); alert("content is "+content); }); } } }); //This can be used for identifying when ever a new resource is added chrome.devtools.inspectedWindow.onResourceAdded.addListener(function (resource){ alert("resources added" + resource.url); alert("resources content added " + resource.content); }); //This can be used to detect when ever a resource code is changed/updated chrome.devtools.inspectedWindow.onResourceContentCommitted.addListener(function(resource,content){ alert("Resource Changed"); alert("New Content " + content); alert("New Resource Object is " + resource); });
After combining all three codes you will receive
Output 1)

Output 2)

Output 3)

Hope this helps :)
Sudarshan
source share