"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PDFViewerBaseUrl = void 0;
exports.patchRevokeObjectURL = patchRevokeObjectURL;
const chromeExtensionUrlBase = 'chrome-extension://standalone-app';
exports.PDFViewerBaseUrl = `${chromeExtensionUrlBase}/pdf-viewer/mabl_pdf_steps.html`;
const REVOKE_OBJECT_TIMEOUT_MILLIS = 10000;
function patchRevokeObjectURL() {
    if (!isPdfEmbedHandlerNeeded()) {
        return;
    }
    const patchScriptElement = document.createElement('script');
    patchScriptElement.id = 'mabl-patch';
    patchScriptElement.innerHTML = `
  (function() {
    if (/native/.test(window.URL.revokeObjectURL)) {
      window.URL.origRevokeObjectURL = window.URL.revokeObjectURL;
      window.URL.revokeObjectURL = function(url) {
        let origURL = url;
        setTimeout(() => {
          window.URL.origRevokeObjectURL(origURL);
        }, ${REVOKE_OBJECT_TIMEOUT_MILLIS});
      };
    }
    let patchElement = document.getElementById('mabl-patch');
    patchElement?.parentNode?.removeChild(patchElement);
  })();
  `;
    try {
        document.body.appendChild(patchScriptElement);
    }
    catch (error) {
        console.error('Issue calling patchRevokeObjectURL', error);
    }
}
function isPdfEmbedHandlerNeeded() {
    return isHtmlPage() && !document.getElementById('mabl-patch');
}
function isHtmlPage() {
    return !!(!window.location.href.startsWith('chrome-extension') &&
        document.doctype?.name?.indexOf('html') !== -1);
}
