(function(){function e(e,t){try{const n=window.webkit;delete window["webkit"];window.webkit.messageHandlers[e].postMessage(t);window.webkit=n}catch(e){}}function t(){const e=new Uint32Array(4);window.crypto.getRandomValues(e);return e.reduce(((e="",t)=>e+t.toString(16).padStart(8,"0")),"")}class n{registeredApis={};frameId=t();registerApi(e,t){if(this.registeredApis[e]!==undefined){throw new Error(`API ${e} already registered.`)}this.registeredApis[e]=t}getRegisteredApi(e){return this.registeredApis[e]}getFrameId(){if(!this.frameId){this.frameId=t()}return this.frameId}registerFrame(){e("FrameBecameAvailable",{crwFrameId:this.getFrameId()})}}if(!window.__gCrWeb){window.__gCrWeb=new n}const i=window.__gCrWeb;function r(){o(0,0)}function o(t,n){const i=window.getSelection();const r={x:0,y:0,width:0,height:0};if(!i||!i.rangeCount){const e=document.getElementsByTagName("iframe");for(const t of e){const e=t.getBoundingClientRect();t.contentWindow?.postMessage({type:"org.chromium.getSelection",offsetX:e.x,offsetY:e.y},"*")}return}const o=i.getRangeAt(0).getClientRects()[0];if(o){r.x=o.x+t;r.y=o.y+n;r.width=o.width;r.height=o.height}const s=`${i?.toString()}`;e("WebSelection",{selectedText:s,selectionRect:r})}i.webSelection={getSelectedText:r};window.addEventListener("message",(function(e){const t=e.data;if(!t||typeof t!=="object"||!t.hasOwnProperty("type")||t.type!=="org.chromium.getSelection"||!t.hasOwnProperty("offsetX")||!t.hasOwnProperty("offsetY")){return}const n=t.offsetX;const i=t.offsetY;o(n,i)}))})();