webview 사용 시 "Cannot read property 'getItem' of null" 오류 해결하기
Post

webview 사용 시 "Cannot read property 'getItem' of null" 오류 해결하기

Problem

기본 브라우저(크롬) 에서는 정상 동작하던 페이지가 webview로 띄우면 아래 오류로 안뜨는 경우가 있다.

1
"Uncaught (in promise) TypeError: Cannot read property 'getItem' of null" 

Cause

webview 에 로컬 저장소 사용이 불가하여 나타나는 문제이다.

Solution

webview 설정시 domStorageEnabled 옵션을 추가해준다.
로컬 저장소 사용여부를 허용해 주는 옵션이다.

1
2
3
4
5
webview.apply {
    webViewClient = WebViewClient()
    settings.javaScriptEnabled = true
    settings.domStorageEnabled = true
}