Skip to content

[Compatibility] Async Module Import - Base Path Difference #1708

Description

@cyfung1031

提交前检查

  • 我已经搜索过现有 issues,并确认问题与某个用户脚本或 userscript API 有关

用户脚本链接

触发问题的目标网站

问题表现与对比

Tampermonkey: true + true
Violentmonkey: true + true
ScriptCat: false + false

// ==UserScript==
// @name         Dynamic Import URL Resolution Test
// @namespace    http://tampermonkey.net/
// @version      0.0.1
// @description  Verify how dynamic import() resolves absolute and relative module paths.
// @author       You
// @match        https://*/*
// @grant        GM_setValue
// ==/UserScript==

(async function () {
    'use strict';

    async function testImportResolution(label, specifier) {
        const expectedUrl = new URL(specifier, document.URL).href;

        let errorMessage = '';

        try {
            await import(specifier);
        } catch (error) {
            errorMessage = String(error?.message ?? error);
        }

        return {
            Test: label,
            Specifier: specifier,
            'Expected URL': expectedUrl,
            Passed: errorMessage.includes(expectedUrl),
            Error: errorMessage,
        };
    }

    const results = await Promise.all([
        // https://github.com/scriptscat/
        // /js/services/test.js
        // → https://github.com/js/services/test.js
        testImportResolution(
            'Absolute path resolves from origin root',
            '/js/services/test.js'
        ),

        // https://github.com/scriptscat/
        // ./js/services/test.js
        // → https://github.com/scriptscat/js/services/test.js
        testImportResolution(
            'Relative path resolves from current page',
            './js/services/test.js'
        ),
    ]);

    console.table(results);
})();

用户脚本 metadata

-

ScriptCat 版本

v1.5.0-beta.2

系统 / 浏览器及版本

Helium latest

最小复现脚本 / 日志 / 截图

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    compatibility其它管理器可以运行,脚本猫不能运行nofix不能修復userscriptIssues related to userscripts and userscript compatibility

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions