Javascript injection into service worker

Viewed 185

I want to inject a Javascript code snippet into a resource fetched by a page, instead of direct injection into the page as described here. More specifically, I want to inject the code snippet into the service-worker code of the page. I have the page url as well as the script-URL. One of the approaches is to set up a system-level proxy and modify response which is cumbersome and is complex. Another possible approach is the modify the fetched resources using selenium while the selenium driver is getting the URL (i.e driver.get(url)). For example, when executing driver.get(url.com), I want to modify url.com/service-worker.js so the page loads with the modified version of the service worker. I am new to this and would appreciate it if anyone has any resource or has done something similar and could share. tldr: I am working with selenium for JS injection into service worker of a page, and need help with injection into service worker code.

0 Answers
Related