대부분의 홈페이지는 모바일 지원을 한다.
pc에서 모바일 페이지를 보고 싶을 경우가 있는데 이럴때 사용하면 좋은 extention이 있다.
User-Agent Switcher for Chrome
https://chrome.google.com/webstore/detail/user-agent-switcher-for-c/djflhoibgkdhkhhcedjiklpkjnoahfmg
설치를 하면 우측 상단에 browser action이 생기는데 누르면 지원하는 agent를 설정 할 수 있다.
android , iphone 등을 선택하면 현재 browser 모드가 설정되고 google.com 에 접속하면 모바일 모드로 보이는 것을 확인 할 수 있다.
chrome exteion을 이용한 것인데 아래 코드로 동작하는 것을 확인 하였다.
요청 하기전 설정된 정보로 User-Agent 헤더 정보를 바꾼다.
function updateListeners() {
if (!listener) {
listener = function(details) {
var header_map = {
requestHeaders : details.requestHeaders
};
if (details && details.url && details.requestHeaders
&& details.requestHeaders.length > 0) {
header_map = {
requestHeaders : replaceHeader(getCacheSpoofValues(
details.url, details.tabId), details.requestHeaders)
}
}
return header_map
}
}
chrome.webRequest.onBeforeSendHeaders.addListener(listener, {
"urls" : [ "http://*/*", "https://*/*" ]
}, [ "requestHeaders", "blocking" ])
}
https://developer.chrome.com/extensions/webRequest
chrome.webRequest
{ "name": "My extension", ... "permissions": [ "webRequest", "*://*.google.com/" ], ... }
request의 라이브사이클 onBeforeSendHeaders 2번째 단계 이다.
onBeforeRequest
(optionally synchronous)onBeforeSendHeaders
(optionally synchronous)onBeforeSendHeaders
event is passed to all subscribers, so different subscribers may attempt to modify the request; see the Implementation details section for how this is handled. This event can be used to cancel the request.onSendHeaders
onHeadersReceived
(optionally synchronous)onAuthRequired
(optionally synchronous)onBeforeRedirect
onResponseStarted
onCompleted
onErrorOccurred
'Chrome extention' 카테고리의 다른 글
현재 탭 jquery 하여 제어하기. (0) | 2015.03.02 |
---|