@@ -300,6 +300,54 @@ export class ScriptService {
300300 }
301301 }
302302 ) ;
303+
304+ {
305+ type Config = Record < string , any > ;
306+ const REMOVE_HEADERS = [
307+ `content-security-policy` ,
308+ `content-security-policy-report-only` ,
309+ `x-webkit-csp` ,
310+ `x-content-security-policy` ,
311+ `x-frame-options` ,
312+ ] ;
313+
314+ const { RuleActionType, HeaderOperation, ResourceType } = chrome . declarativeNetRequest ;
315+
316+ const rules : chrome . declarativeNetRequest . Rule [ ] = [
317+ {
318+ id : 2001 ,
319+ action : {
320+ type : RuleActionType . MODIFY_HEADERS ,
321+ responseHeaders : REMOVE_HEADERS . map ( ( header ) => ( {
322+ operation : HeaderOperation . REMOVE ,
323+ header,
324+ } ) ) ,
325+ } ,
326+ condition : {
327+ urlFilter : `|http*` ,
328+ resourceTypes : [ ResourceType . MAIN_FRAME , ResourceType . SUB_FRAME ] ,
329+ } ,
330+ } ,
331+ ] ;
332+
333+ const updateRules = ( newConfig : Config , oldConfig ?: Config ) => {
334+ if ( oldConfig && newConfig . csp_http_disabled === oldConfig ?. csp_http_disabled ) {
335+ return ;
336+ }
337+ if ( newConfig . csp_http_disabled ) {
338+ chrome . declarativeNetRequest . updateDynamicRules ( {
339+ removeRuleIds : rules . map ( ( rule ) => rule . id ) ,
340+ addRules : rules ,
341+ } ) ;
342+ } else {
343+ chrome . declarativeNetRequest . updateDynamicRules ( {
344+ removeRuleIds : rules . map ( ( rule ) => rule . id ) ,
345+ } ) ;
346+ }
347+ } ;
348+
349+ updateRules ( { csp_http_disabled : true } ) ;
350+ }
303351 }
304352
305353 public async openInstallPageByUrl (
0 commit comments