module.exports = "(function(e,t,r){var n=r(5894),i=r(4727).Promise,a=r(7358),s=r(4527),o=r(1571),d=r(343),m=r(280).v,u=r(9404),g=r(8737),_=r(4934),c=r(8131),E=r(7887),f=r(7152),I=r(4810),l=s.get(\"stores/xdomain\"),D=t.Error=m(\"XDomainStorageError\");function p(e){var t;if(!n.find(l.getFrames(),{origin:e.origin}))return I.debug(\"XDomain\",\"No frame found for origin: \"+e.origin),void 0;try{t=_.parse(e.data)}catch(t){return I.debug(\"XDomain\",\"Ignoring malformed message event:\",e),void 0}if(\"ERROR\"===t.type)o.dispatch(a.XDOMAIN_SET_DISABLED,{disabled:!0}),d.emitInternalError(new D(\"Xdomain Error: \"+t.response));else if(\"SYNC\"===t.type)(__PROFILE__||__RUM_VERBOSE__)&&r(9256).time(\"xdomainStorageSync\"),n.each(l.getSubscribers(),(function(e){e(t.response.key,t.response.value)})),(__PROFILE__||__RUM_VERBOSE__)&&r(9256).timeEnd(\"xdomainStorageSync\");else{var i=l.getMessageById(t.id);if(!i){if(I.warn(\"XDomain\",\"No stored message found for ID\",t.id),n.isNumber(t.id)){var s=l.getNextMessageId();t.id>=s?d.emitInternalError(new D(\"Message ID is greater than expected maximum ID (\"+t.id+\">\"+s+\")\")):t.id<0?d.emitInternalError(new D(\"Message ID is < 0: \"+t.id)):d.emitInternalError(new D(\"No stored message found for message ID: \"+t.id))}else d.emitInternalError(new D(\"Message ID is not a number: \"+t.id));return}if(!i.resolver)return I.warn(\"XDomain\",\"Message already resolved, ignoring:\",t.id),void 0;i.resolver(t.response),o.dispatch(a.XDOMAIN_SET_MESSAGE,{messageId:t.id,message:{data:{id:t.id,type:i.data.type,key:i.data.key},startTime:i.startTime,endTime:u.now()}})}}function y(e,t){return t||(t=l.getDefaultFrame()),new i((function(r){var i={data:n.extend({},e,{id:l.getNextMessageId()}),resolver:r};t?l.isDisabled()||S(i,t):o.dispatch(a.XDOMAIN_SET_MESSAGE,{messageId:i.data.id,message:i})}))}function S(e,t){var r=e.data;o.dispatch(a.XDOMAIN_SET_MESSAGE,{messageId:e.data.id,message:n.extend({},e,{startTime:u.now()})}),t.target.postMessage(_.stringify(r),t.origin)}t.setItem=function(e,t,r){return y({type:\"PUT\",key:e,value:t},r)},t.getItem=function(e,t){return y({type:\"GET\",key:e},t)},t.fetchAll=function(e){return y({type:\"GETALL\"},e)},t.deleteData=function(e,t){return y({type:\"DELETE\",visitorId:e},t)},t.subscribe=function(e){o.dispatch(a.XDOMAIN_ADD_SUBSCRIBER,{subscriber:e})},t.loadIframe=function(e,t){return new i((function(n){(__PROFILE__||__RUM_VERBOSE__)&&r(9256).time(\"xdomainIframeLoad\");var i=g.createElement(\"iframe\");i.src=e+t,i.hidden=!0,i.setAttribute(\"tabindex\",\"-1\"),i.setAttribute(\"title\",\"Optimizely Internal Frame\"),i.style.display=\"none\",i.height=0,i.width=0,i.onload=function(){(__PROFILE__||__RUM_VERBOSE__)&&r(9256).timeEnd(\"xdomainIframeLoad\");var s={id:l.getNextFrameId(),target:i.contentWindow,origin:e,path:t};o.dispatch(a.XDOMAIN_ADD_FRAME,s),n(s)},g.appendTo(g.querySelector(\"body\"),i)}))},t.getXDomainUserId=function(e,t){var r,i={},a=n.keys(e);return n.each(t,(function(e){i[e]=[],n.each(a,(function(t){var a=E.getUserIdFromKey(t,e);!r&&a&&(r=a),a&&!n.includes(i[e],a)&&i[e].push(a)}))})),I.debug(\"XDomain: Found userIds:\",i),r},t.load=function(e,r){f.addEventListener(\"message\",p);return c.pollFor((function(){return!!g.querySelector(\"body\")})).then((function(){return t.loadIframe(e,r)})).then((function(e){o.dispatch(a.XDOMAIN_SET_DEFAULT_FRAME,e),l.isDisabled()||n.each(l.getMessages(),(function(t){t.startTime||S(t,e)}))}))}})";