donobu
Version:
Create browser automations with an LLM agent and replay them as Playwright scripts.
50 lines • 1.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.installDonobuNamespace = installDonobuNamespace;
/**
* Ensures the shared Donobu namespace exists exactly once as a non-writable,
* non-configurable data property on window.
*/
function installDonobuNamespace() {
const DONOBU_KEY = '__donobu';
const existing = Object.getOwnPropertyDescriptor(window, DONOBU_KEY);
if (!existing) {
Object.defineProperty(window, DONOBU_KEY, {
value: Object.create(null),
enumerable: false,
writable: false,
configurable: false,
});
return;
}
// Leave already locked-down data properties alone.
if (!existing.configurable &&
existing.writable === false &&
'value' in existing) {
return;
}
if (!existing.configurable) {
// If the property is non-configurable but still writable, tighten it without
// changing other immutable attributes such as enumerability.
if ('value' in existing && existing.writable) {
Object.defineProperty(window, DONOBU_KEY, {
value: existing.value ?? Object.create(null),
enumerable: existing.enumerable ?? false,
writable: false,
configurable: false,
});
}
return;
}
// For configurable or accessor properties, redefine with the expected shape.
const value = 'value' in existing && existing.value !== null
? existing.value
: Object.create(null);
Object.defineProperty(window, DONOBU_KEY, {
value,
enumerable: false,
writable: false,
configurable: false,
});
}
//# sourceMappingURL=donobu-namespace.js.map