IssuesModel.js 1.3 KB

12345678910
  1. class Issue{constructor(category,name,data){this._category=category;this._name=name;this._data=data;}}
  2. Issue.Categories={SameSite:Symbol('SameSite'),};const connectedIssuesSymbol=Symbol('issues');export default class IssuesModel extends SDK.SDKModel{constructor(target){super(target);const networkManager=target.model(SDK.NetworkManager);if(networkManager){networkManager.addEventListener(SDK.NetworkManager.Events.RequestFinished,this._handleRequestFinished,this);}
  3. this._issues=[];}
  4. static connectWithIssue(obj,issue){if(!obj){return;}
  5. if(!obj[connectedIssuesSymbol]){obj[connectedIssuesSymbol]=[];}
  6. obj[connectedIssuesSymbol].push(issue);}
  7. static hasIssues(obj){if(!obj){return false;}
  8. return obj[connectedIssuesSymbol]&&obj[connectedIssuesSymbol].length;}
  9. _handleRequestFinished(event){const request=(event.data);const blockedResponseCookies=request.blockedResponseCookies();for(const blockedCookie of blockedResponseCookies){const reason=blockedCookie.blockedReasons[0];const cookie=blockedCookie.cookie;const issue=new Issue(Issue.Categories.SameSite,reason,{request,cookie});IssuesModel.connectWithIssue(request,issue);IssuesModel.connectWithIssue(cookie,issue);}}}
  10. self.SDK=self.SDK||{};SDK=SDK||{};SDK.IssuesModel=IssuesModel;SDK.SDKModel.register(IssuesModel,SDK.Target.Capability.None,true);