I'm building an extension (MV3
) that will make demoing data in apps easier (ie. pumping fake data into a chart to make it more realistic than typical fake demo data).
My current approach is to take a user-inputted endpoint (ie. api.acme.com/reporting/chart
) and a user-inputted override response (ie. data: [ {x:3, y:1}, {x:5, y:2} ]
) and then use chrome.declarativeNetRequest.updateDynamicRules
to create a redirecting
rule where the redirectUrl is actually a dynamically created dataUri like so:
{
"id": idVariable,
"priority": 1,
"action" : { "type" : "redirect", "redirect": {
"url": `data:application/json;charset=utf-8;base64,${btoa(remix.response)}`
}},
"condition" : {
"urlFilter": endpointVariable
}
}
(As an aside, I'm curious if the redirect
and dataUri
response method is common, a generally accepted approach or if I've over-engineered.)
Most pressing, I've noticed many apps are not using query params to filter their reporting APIs but rather the body payload of a POST
request. In some rare cases, I've even seen a single /reports
endpoint where the body itself is responsible for defining the type of report to pull. I understand the point of DNR is to prioritize security of the user but is it possible to expose the requests' body?