diff --git a/web/static/coffee/har/editor.coffee b/web/static/coffee/har/editor.coffee index b8f9e11c016..b8708b27a91 100644 --- a/web/static/coffee/har/editor.coffee +++ b/web/static/coffee/har/editor.coffee @@ -55,14 +55,19 @@ define (require, exports, module) -> window.addEventListener("message", (ev) -> if event.origin != window.location.origin return - cookie = ev.data cookie_str = "" - for key, value of cookie - cookie_str += key + '=' + value + '; ' - if cookie_str == '' - console.log('没有获得cookie, 您是否已经登录?') + # 排除未带特定key的postMessage + if !cookie.info return + if cookie.info == 'cookieRaw' + for key, value of cookie.data + cookie_str += key + '=' + value + '; ' + if cookie_str == '' + console.log('没有获得cookie, 您是否已经登录?') + return + else if cookie.info == 'get-cookieModReady' + cookie_str = "get-cookie扩展已就绪" cookie_input?.val(cookie_str) cookie_input?.scope().$parent.var.value = cookie_str ) @@ -74,4 +79,6 @@ define (require, exports, module) -> 'entry_editor' ]) - init: -> angular.bootstrap(document.body, ['HAREditor']) + { init: -> + angular.bootstrap(document.body, ['HAREditor']) + } diff --git a/web/static/har/editor.js b/web/static/har/editor.js index 5ba13d56211..7c8d91b5894 100644 --- a/web/static/har/editor.js +++ b/web/static/har/editor.js @@ -55,20 +55,28 @@ }); // deepcode ignore InsufficientPostmessageValidation: the event.origin is checked window.addEventListener("message", function(ev) { - var cookie, cookie_str, key, value; + var cookie, cookie_str, key, ref, value; if (event.origin !== window.location.origin) { return; } cookie = ev.data; cookie_str = ""; - for (key in cookie) { - value = cookie[key]; - cookie_str += key + '=' + value + '; '; - } - if (cookie_str === '') { - console.log('没有获得cookie, 您是否已经登录?'); + if (!cookie.info) { return; } + if (cookie.info === 'cookieRaw') { + ref = cookie.data; + for (key in ref) { + value = ref[key]; + cookie_str += key + '=' + value + '; '; + } + if (cookie_str === '') { + console.log('没有获得cookie, 您是否已经登录?'); + return; + } + } else if (cookie.info === 'get-cookieModReady') { + cookie_str = "get-cookie扩展已就绪"; + } if (cookie_input != null) { cookie_input.val(cookie_str); } diff --git a/web/tpl/utils.html b/web/tpl/utils.html index 80802433e05..4e97fb7799f 100644 --- a/web/tpl/utils.html +++ b/web/tpl/utils.html @@ -175,19 +175,30 @@