Study/Etc.

[크롬/Chrome] local file 문서 간 데이터 교환 오류 문제 - (SecurityError: Blocked a frame with origin)

빨간당무 2015. 4. 9. 12:15

local file을 크롬 브라우저로 보는 상황에서

A 문서에서 B 문서를 띄우고 (Parent Window - Child Window) 

B 문서에서 A 문서의 DOM으로 접속하여 데이터를 보내려는 경우 아래와 같은 에러 메세지를 개발자콘솔창에서 볼 수 있다. 


Uncaught SecurityError: Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match. 


실제 웹서버로 올려서 실행하는 경우에는 발생하지 않는 문제이나 개발자 테스트 중에 발생 될 수 있는 문제이며, 

파이어폭스에서는 정상적으로 수행이 된다. 

이는 크롬의 보안 정책이 특정 버전 이후로 강화되어서 라고 한다. 


대처 방법으로는 크롬실행시 아래와 같은 옵션을 추가하면 된다. 


--disable-web-security 


혹은 


크롬 웹스토어에서 확장프로그램으로 아래 기능을 추가하면 된다. 


 Allow-Control-Allow-Origin: *


링크는 아래와 같다. 


https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi


위 방법은 Ajax 로 다른 도메인(cross domain)에 접근하면 문제가 발생한다고 하며 동일하게 해결 할 수도 있다. 


reference : http://www.chromium.org/developers/how-tos/run-chromium-with-flags

reference : http://jongkwang.com/?p=852