/* Wombat.js client-side rewriting engine for web archive replay Copyright (C) 2014-2023 Webrecorder Software, Rhizome, and Contributors. Released under the GNU Affero General Public License. This file is part of wombat.js, see https://github.com/webrecorder/wombat.js for the full source Wombat.js is part of the Webrecorder project (https://github.com/webrecorder) This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ function WBWombat(info){return this instanceof WBWombat?void(this.info=info,this.initImportScriptsRewrite(),this.initHTTPOverrides(),this.initClientApisOverride(),this.initCacheApisOverride()):new WBWombat(info)}WBWombat.prototype.noRewrite=function(url){return!url||url.indexOf("blob:")===0||url.indexOf("javascript:")===0||url.indexOf("data:")===0||url.indexOf(this.info.prefix)===0},WBWombat.prototype.isRelURL=function(url){return url.indexOf("/")===0||url.indexOf("http:")!==0},WBWombat.prototype.maybeResolveURL=function(maybeRelURL,against){if(!against)return maybeRelURL;try{var resolved=new URL(maybeRelURL,against);return resolved.href}catch(e){}return maybeRelURL},WBWombat.prototype.ensureURL=function(url,resolveAgainst){if(!url)return url;var newURL;switch(typeof url){case"string":newURL=url;break;case"object":newURL=url.toString();break;default:return null;}return this.noRewrite(newURL)?null:this.isRelURL(newURL)?this.maybeResolveURL(newURL,resolveAgainst):newURL.indexOf(self.location.origin)===0?this.maybeResolveURL(newURL.slice(self.location.origin.length),resolveAgainst):newURL},WBWombat.prototype.rewriteURL=function(url){var rwURL=this.ensureURL(url,this.info.originalURL);return rwURL?this.info.prefixMod?this.info.prefixMod+rwURL:rwURL:url},WBWombat.prototype.rewriteClientWindowURL=function(url,client){var rwURL=this.ensureURL(url,client?client.url:this.info.originalURL);return rwURL?this.info.prefix?this.info.prefix+"mp_/"+rwURL:rwURL:url},WBWombat.prototype.rewriteWSURL=function(originalURL){if(!originalURL)return originalURL;var urltype_=typeof originalURL,url=originalURL;if(urltype_==="object")url=originalURL.toString();else if(urltype_!=="string")return originalURL;if(!url)return url;var wsScheme="ws://",wssScheme="wss://",https="https://",wbSecure=this.info.prefix.indexOf(https)===0,wbPrefix=this.info.prefix.replace(wbSecure?https:"http://",wbSecure?wssScheme:"ws://")+"ws_/";return wbPrefix+url},WBWombat.prototype.rewriteArgs=function(argsObj){for(var newArgObj=new Array(argsObj.length),i=0;i