원본 : https://developer.chrome.com/extensions/webRequest.html
사용법이 애매하다. 문서를 봐도 모르겠다. 차라리 예제가 빠르다
1. 아래와 같이 적절히 manifest.json파일을 설정한다
"permissions": ["webRequest", "webRequestBlocking",
"http://*.limsungguk.com/"],
"background": {
"scripts": ["loldogs.js", "background.js"]
},
2. background.js 에 이벤트 등록
chrome.webRequest.onBeforeRequest.addListener(foo,filter,extra);
처럼 등록을 한다.
여기서 filter는 문서상 RequestFilter라고 나오는 부분이다.
onBeforeRequest 뿐만아니라
onBeforeSendHeaders , onSendHeaders, onHeadersReceived 등등 원하는 이벤트를 등록해준다.콜백으로 오는 함수가 리턴하는 값을 설정해주는 값에 따라 적절한 기능을 하는데
아래와 같은 것들 BlockingResponse 할수있다.. network request를 수정가능하게 해준다는 의미다.. 어떤 이벤트에 어떤 값을 리턴할수있는지 확인하자..
BlockingResponse
responseHeaders if you really want to modify the headers in order to limit the number of conflicts (only one extension may modifyresponseHeaders for each request).
No comments:
Post a Comment