대부분의 홈페이지는 모바일 지원을 한다. 

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

request 요청중의 관찰, 트래픽분석, blocking ,intercept 할 때 사용한다.

사용시 아래 권한을 준다.
      {
        "name": "My extension",
        ...
        "permissions": [
          "webRequest",
          "*://*.google.com/"
        ],
        ...
      }
      

request의 라이브사이클 onBeforeSendHeaders 2번째 단계 이다.

Life cycle of a web request from the perspective of the webrequest API

onBeforeRequest (optionally synchronous)
Fires when a request is about to occur. This event is sent before any TCP connection is made and can be used to cancel or redirect requests.
onBeforeSendHeaders (optionally synchronous)
Fires when a request is about to occur and the initial headers have been prepared. The event is intended to allow extensions to add, modify, and delete request headers (*). The 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
Fires after all extensions have had a chance to modify the request headers, and presents the final (*) version. The event is triggered before the headers are sent to the network. This event is informational and handled asynchronously. It does not allow modifying or cancelling the request.
onHeadersReceived (optionally synchronous)
Fires each time that an HTTP(S) response header is received. Due to redirects and authentication requests this can happen multiple times per request. This event is intended to allow extensions to add, modify, and delete response headers, such as incoming Set-Cookie headers. The caching directives are processed before this event is triggered, so modifying headers such as Cache-Control has no influence on the browser's cache. It also allows you to redirect the request.
onAuthRequired (optionally synchronous)
Fires when a request requires authentication of the user. This event can be handled synchronously to provide authentication credentials. Note that extensions may provide invalid credentials. Take care not to enter an infinite loop by repeatedly providing invalid credentials.
onBeforeRedirect
Fires when a redirect is about to be executed. A redirection can be triggered by an HTTP response code or by an extension. This event is informational and handled asynchronously. It does not allow you to modify or cancel the request.
onResponseStarted
Fires when the first byte of the response body is received. For HTTP requests, this means that the status line and response headers are available. This event is informational and handled asynchronously. It does not allow modifying or cancelling the request.
onCompleted
Fires when a request has been processed successfully.
onErrorOccurred
Fires when a request could not be processed successfully.


'Chrome extention' 카테고리의 다른 글

현재 탭 jquery 하여 제어하기.  (0) 2015.03.02
Posted by 마법수정화살
,

https://developer.chrome.com/extensions/samples 페이지의 아래 예제를 받아서 수정.

A browser action with a popup that changes the page color


이 예제는 browser action을 클릭 했을 때 현재 탭 컨텐츠의 바탕화면 색을 변경한다. 

function click(e) {

  chrome.tabs.executeScript(null,

      {code:"document.body.style.backgroundColor='" + e.target.id + "'"});

  window.close();

}


이 것을 응용해서 편리한, 개발자도구를 못 쓰는 사용자를 위한 도구를 만들려고 했다. 

그런데 일반 java script말고 jquery를 이용해 컨텐츠를 파싱하거나 조작하려고 하였으나 잘 되지 않았다. 


아래와 같이 작성하면 jquery를 이용하여 tab의 컨텐츠를 컨트롤 할 수 있다. 

function handleClick(e) {

  chrome.tabs.executeScript(null, { file: "jquery-1.7.2.js" }, function() {

    chrome.tabs.executeScript(null,{

      code:"$('#members_scroller').css('max-height','100%');"

      });

});

  /*

  chrome.tabs.executeScript(null,

      {code:"var x = document.getElementById('members_scroller').style.maxHeight = '100%';"});

  */

}


chrome.browserAction.onClicked.addListener(handleClick);


https://developer.chrome.com/extensions/tabs#method-executeScript

executeScript

chrome.tabs.executeScript(integer tabId, object details, function callback)
- tabid가 없을경우 기본적으로 현재창의 활성화된 탭에서 실행 된다.
- 먼저 jquery 가 실행되고 callback으로 실행되는 executeScript 에서 jquery를 사용 할 수 있다.

이 기능을 사용하기 위해서는 menifest.js 에 아래 퍼미션을 추가한다. 
"permissions": [
  "activeTab"
],



'Chrome extention' 카테고리의 다른 글

PC 에서 모바일 페이지 접속  (0) 2015.03.02
Posted by 마법수정화살
,

Error validating server certificate 에러를 뱉으며 svn이 접속이 되지 않는다. 

tortoies 사용하는데 해당 서버는 계속 접속이 되지 않는다.

web에서는 잘 접속된다. 


이럴경우 

eclipse, tortoies 에서 해당 svn 인증이 실패하므로 저장된 ssl을 날려버리고 핑거프린트를 다시 한다.

mac이나 linux는 ssl 인증이 저장 된걸 날려버리면 해결이 되지만 windows 의 경우 그 경로가 어딘지 알 수 없다. 

windows7 기준으로 설명.


실행 > %APPDATA%\Subversion\auth 으로 이동> svn.ssl.server 디렉토리 삭제. 


아래는 참조.

https://kthoms.wordpress.com/2011/03/17/fixing-subversion-problem-error-validating-server-certificate/

Fixing subversion problem “Error validating server certificate”

I have faced the annoying problem that for unknown reasons I got a security exception when accessing the subversion repository for one of my Google Code projects. This used to work before, but maybe the server has been changed. However, if the certificate is not trusted subversion will ask you whether you trust the certificate and if you want to add this certifacte.

svn info https://svn.codespot.com/a/eclipselabs.org/xtext-utils/subprojects/unittesting/branches
Error validating server certificate for 'https://svn.codespot.com:443':
 - The certificate is not issued by a trusted authority. Use the
   fingerprint to validate the certificate manually!
Certificate information:
 - Hostname: *.googlecode.com
 - Valid: from Wed, 16 Feb 2011 00:27:28 GMT until Thu, 16 Feb 2012 00:37:28 GMT
 - Issuer: Google Inc, US
 - Fingerprint: 34:4b:90:e7:e3:36:81:0d:52:1f:10:c0:4c:98:66:90:4a:9e:05:c9
(R)eject, accept (t)emporarily or accept (p)ermanently?

The problem now is that even if I entered the “p” option the next time I access SVN the same exception occurs again.

My issue was solved now by cleaning the directory “~/.subversion/auth/svn.ssl.server”.

 rm ~/.subversion/auth/svn.ssl.server/*



http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-dug.html

Authentication

If the repository that you are trying to access is password protected, an authentication Dialog will show up.

Figure 4.5. Authentication Dialog

Authentication Dialog


Enter your username and password. The checkbox will make TortoiseSVN store the credentials in Subversion's default directory:%APPDATA%\Subversion\auth in three subdirectories:

  • svn.simple contains credentials for basic authentication (username/password). Note that passwords are stored using the WinCrypt API, not in plain text form.

  • svn.ssl.server contains SSL server certificates.

  • svn.username contains credentials for username-only authentication (no password needed).

If you want to clear the authentication cache for all servers, you can do so from the Saved Data page of TortoiseSVN's settings dialog. That button will clear all cached authentication data from the Subversion auth directories, as well as any authentication data stored in the registry by earlier versions of TortoiseSVN. Refer to the section called “Saved Data Settings”.

If you want to clear authentication for one realm only then you will have to dig into those directories, find the file which contains the information you want to clear and delete the file.

Some people like to have the authentication data deleted when they log off Windows, or on shutdown. The way to do that is to use a shutdown script to delete the %APPDATA%\Subversion\auth directory, e.g.

@echo off
rmdir /s /q "%APPDATA%\Subversion\auth"

You can find a description of how to install such scripts at http://www.windows-help-central.com/windows-shutdown-script.html .

For more information on how to set up your server for authentication and access control, refer to the section called “Accessing the Repository”.

'WINDOWS' 카테고리의 다른 글

windows7 우클릭 반응속도 느릴때  (0) 2016.11.25
windows의 cpu 성능 모니터링  (0) 2014.10.08
http를 이용한 ping 테스트  (0) 2014.06.12
Posted by 마법수정화살
,