Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

自己写的web extension无法加载入口js文件 #65

Open
huanghuixin1 opened this issue Aug 3, 2023 · 8 comments
Open

自己写的web extension无法加载入口js文件 #65

huanghuixin1 opened this issue Aug 3, 2023 · 8 comments

Comments

@huanghuixin1
Copy link

已经加了browser字段,并且package.json是正常加载的,但是入口文件没有请求。
代码是参考vscode的webextension例子
package.json文件如下:

{
  "name": "webext2",
  "displayName": "webext2",
  "description": "",
  "version": "0.0.1",
  "engines": {
    "vscode": "^1.80.0"
  },
  "categories": [
    "Other"
  ],
  "activationEvents": [],
  "browser": "./dist/web/extension.js",
  "contributes": {
    "commands": [
      {
        "command": "webext2.helloWorld",
        "title": "Hello World"
      }
    ]
  },
  "scripts": {
    "test": "vscode-test-web --browserType=chromium --extensionDevelopmentPath=. --extensionTestsPath=dist/web/test/suite/index.js",
    "pretest": "yarn run compile-web",
    "vscode:prepublish": "yarn run package-web",
    "compile-web": "webpack",
    "watch-web": "webpack --watch",
    "package-web": "webpack --mode production --devtool hidden-source-map",
    "lint": "eslint src --ext ts",
    "run-in-browser": "vscode-test-web --browserType=chromium --extensionDevelopmentPath=. .",
    "server": "npx serve --cors -l 5000 --ssl-cert ./certs/localhost.pem --ssl-key ./certs/localhost-key.pem"
  },
  "devDependencies": {
    "@types/vscode": "^1.80.0",
    "@types/mocha": "^10.0.1",
    "eslint": "^8.41.0",
    "@typescript-eslint/eslint-plugin": "^5.59.8",
    "@typescript-eslint/parser": "^5.59.8",
    "mocha": "^10.2.0",
    "typescript": "^5.1.3",
    "@vscode/test-web": "^0.0.44",
    "ts-loader": "^9.4.3",
    "webpack": "^5.85.0",
    "webpack-cli": "^5.1.1",
    "@types/webpack-env": "^1.18.1",
    "assert": "^2.0.0",
    "process": "^0.11.10"
  }
}

此时按F1运行Hello Work的cmd会报错
image

然后看chrome的network是可以找到这个package.json的加载,但是找不到extension文件的加载
image

此外,有没有带入口js文件的webextension可以参考一下

@huanghuixin1
Copy link
Author

运行的是Hello Word,上面打错了

@erha19
Copy link
Member

erha19 commented Aug 3, 2023

@huanghuixin1 你的 activationEvents 没有声明,试试加个 *? 参考 https://code.visualstudio.com/api/references/activation-events

@huanghuixin1
Copy link
Author

huanghuixin1 commented Aug 3, 2023

加上了也不行,调整了一下格式如下

{
  "name": "webext2",
  "displayName": "webext2",
  "description": "",
  "version": "0.0.1",
  "publisher": "hx",
  "preview": true,
  "engines": {
    "kaitian": "*",
    "vscode": "^1.31.1",
    "node": ">=10.2.0"
  },
  "categories": [
    "Other"
  ],
  "activationEvents": [
    "*"
  ],
  "browser": "./dist/web/extension.js",
  "contributes": {
    "commands": [
      {
        "command": "webext2.helloWorld",
        "title": "Hello World"
      }
    ]
  }
}

@erha19

@erha19
Copy link
Member

erha19 commented Aug 3, 2023

@huanghuixin1 参照一下这两个案例:
helloworld-web-sample
lsp-web-extension-sample

@huanghuixin1
Copy link
Author

@erha19 感谢回复
这个我其实之前就看过,然后又拿过来仔细测了一下还是不行。
现在问题是,除了入口js文件不加载,其他都正常。包括主题插件里的样式和图标

然后我看了下core项目中extension包,但我没找到入口js加载对应的逻辑在哪里

@AhkunTa
Copy link
Member

AhkunTa commented Aug 3, 2023

@erha19 感谢回复 这个我其实之前就看过,然后又拿过来仔细测了一下还是不行。 现在问题是,除了入口js文件不加载,其他都正常。包括主题插件里的样式和图标

然后我看了下core项目中extension包,但我没找到入口js加载对应的逻辑在哪里

你插件有build过吗 加载插件的话 根据 package.json browser来加载插件js 确认下你插件下 有 ./dist/web/extension.js 这个吗

或者看下有没有加载的具体报错信息

@huanghuixin1
Copy link
Author

@AhkunTa 肯定是build过的,而且就算没有也应该会有请求的记录报404,但实际的结果是没有请求。问题就出在没有报错信息。

并且我发现这个插件,就是官方提供的alex-ext-public.typescript-language-features-worker,他里面也有browser字段,但是也没有请求extension.js

@AhkunTa
Copy link
Member

AhkunTa commented Aug 3, 2023

@huanghuixin1 https://github.com/opensumi/core/blob/main/packages/extension/src/browser/extension-worker.service.ts#L66 这里是worker插件的初始化逻辑 可以debug看下这个插件在这里有没有初始化 很大概率是激活插件出了问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants