Skip to content

onnxruntime-web dependency on document breaks chrome serviceworker #23214

@abbasvalliani

Description

@abbasvalliani

Describe the issue

I am migrating from onnxruntime-web from 1.18 to 1.20 and the code breaks since onnxruntime-web specifically includes the document object which is not available in the serviceworker in a chrome extension. This is the snippet that gets compiled:

Version 1.20.1:

background.iife.js:

br = (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("background.iife.js", document.baseURI).href) ?? (typeof document < "u" ? (_a = document.currentScript) == null ? void 0 : _a.src : typeof self < "u" ? (_b2 = self.location) == null ? void 0 : _b2.href : void 0), Sg = typeof location > "u" ? void 0 : location.origin, Ag = (i, e) => {

Version 1.18

background.iife.js:
/*!

  • ONNX Runtime Web v1.18.0
  • Copyright (c) Microsoft Corporation. All rights reserved.
  • Licensed under the MIT License.
    */
    var vd = Object.create;
    var Pn = Object.defineProperty;
    var _d = Object.getOwnPropertyDescriptor;
    var Od = Object.getOwnPropertyNames;
    var Id = Object.getPrototypeOf, Sd = Object.prototype.hasOwnProperty;
    var L = (a, t) => () => (a && (t = a(a = 0)), t);
    var me = (a, t) => () => (t || a((t = { exports: {} }).exports, t), t.exports), Sr = (a, t) => {
    for (var o in t) Pn(a, o, { get: t[o], enumerable: true });

.... no dependency on document on load.

Any thoughts would be much appreciated. I cannot run onnxruntime-web in a content script due to performance constraints and responsiveness.

To reproduce

N/A since the description is relatively self-explanatory. If needed, I am happy to make a simple chrome extension.

Urgency

This is critical. I cannot upgrade any extension to the most recent codebase.

ONNX Runtime Installation

Built from Source

ONNX Runtime Version or Commit ID

1.20.1

Execution Provider

'wasm'/'cpu' (WebAssembly CPU)

Metadata

Metadata

Assignees

No one assigned

    Labels

    platform:webissues related to ONNX Runtime web; typically submitted using templatestaleissues that have not been addressed in a while; categorized by a bot

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions