UNPKG

@mtdt.temp/browser-core

Version:
39 lines 1.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.makePublicApi = makePublicApi; exports.defineGlobal = defineGlobal; const catchUserErrors_1 = require("../tools/catchUserErrors"); const monitor_1 = require("../tools/monitor"); const display_1 = require("../tools/display"); function makePublicApi(stub) { const publicApi = { version: "dev", // This API method is intentionally not monitored, since the only thing executed is the // user-provided 'callback'. All SDK usages executed in the callback should be monitored, and // we don't want to interfere with the user uncaught exceptions. onReady(callback) { callback(); }, ...stub, }; // Add a "hidden" property to set debug mode. We define it that way to hide it // as much as possible but of course it's not a real protection. Object.defineProperty(publicApi, '_setDebug', { get() { return monitor_1.setDebugMode; }, enumerable: false, }); return publicApi; } function defineGlobal(global, name, api) { const existingGlobalVariable = global[name]; if (existingGlobalVariable && !existingGlobalVariable.q && existingGlobalVariable.version) { display_1.display.warn('SDK is loaded more than once. This is unsupported and might have unexpected behavior.'); } global[name] = api; if (existingGlobalVariable && existingGlobalVariable.q) { existingGlobalVariable.q.forEach((fn) => (0, catchUserErrors_1.catchUserErrors)(fn, 'onReady callback threw an error:')()); } } //# sourceMappingURL=init.js.map