Skip to content

Commit 12c7be9

Browse files
authored
Merge pull request #56 from harlen1212/feature_manifest_v3
Upgrade manifest v3
2 parents 14483fc + ff5298e commit 12c7be9

File tree

7 files changed

+40
-31
lines changed

7 files changed

+40
-31
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
在chrome中输入`chrome://extensions`打开扩展程序,打开[插件下载地址](https://github.com/jd-opensource/micro-app-chrome-plugin/releases),选择最新Release包的`micro-app-chrome-plugin.zip`
1515
文件下载,无需解压,将已下载的插件拖入。
1616

17+
在仅支持 `Manifest V3` 扩展的 Chrome 139+ 浏览器上,请使用 `Micro-App-DevTools V2+` 版本。
18+
19+
> 注:若仍需使用`Micro-App-DevTools V1+`版本,请在仍支持 `Manifest V2` 拓展的 Chrome 138 或更早版本浏览器的地址栏输入 `chrome://flags/#allow-legacy-mv2-extensions` 并启用允许加载旧版 `Manifest V2` 扩展选项。![扩展程序](https://zeromock.s3.cn-north-1.jdcloud-oss.com/micro-app/mv2.png)
20+
1721
![扩展程序](https://img12.360buyimg.com/imagetools/jfs/t1/119438/16/38287/53001/646b50e3F9012f2e8/3bba9844bbb1431b.png)
1822

1923
# 功能
@@ -37,7 +41,7 @@
3741

3842
![路由](https://zeromock.s3.cn-north-1.jdcloud-oss.com/micro-app/communicate.png)
3943

40-
### 4、子应用开发环境模拟
44+
### 4、子应用开发环境模拟(仅插件 v1 版本支持)
4145
点击按钮跳转至功能一中子应用开发环境模拟页面,此处模仿内嵌子应用,使用说明如下所示:
4246

4347
在子应用开发环境模拟页面中输入子页面`URL`等信息

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "micro-app-chrome-extension",
3-
"version": "0.0.1",
3+
"version": "2.0.0",
44
"description": "A chrome extension for debug micro app project.",
55
"license": "MIT",
66
"repository": {
@@ -119,4 +119,4 @@
119119
"webpackbar": "^5.0.2",
120120
"yargs": "^17.4.1"
121121
}
122-
}
122+
}

src/manifest.json

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"manifest_version": 2,
2+
"manifest_version": 3,
33
"name": "Micro App Developer Tools",
44
"short_name": "Sample Extension",
55
"description": "A chrome extension for debug micro app project.",
66
"homepage_url": "https://github.com/reduxjs/redux-devtools",
77
"version": "0.0.1",
8-
"browser_action": {
8+
"action": {
99
"default_popup": "popup-app.html",
1010
"default_icon": {
1111
"128": "static/icons/icon-128-disable.png"
@@ -15,7 +15,9 @@
1515
"128": "static/icons/icon-128.png",
1616
"256": "static/icons/icon-128-disable.png"
1717
},
18-
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
18+
"content_security_policy": {
19+
"extension_pages": "script-src 'self'; object-src 'self'"
20+
},
1921
"background": { "service_worker": "js/background-script.bundle.js" },
2022
"options_page": "options-app.html",
2123
"content_scripts": [
@@ -26,23 +28,22 @@
2628
}
2729
],
2830
"devtools_page": "devtools-loader.html",
29-
"host_permissions": [
30-
"*://*.jd.com/"
31-
],
3231
"permissions": [
3332
"cookies",
3433
"webRequest",
35-
"webRequestBlocking",
36-
"http://*/*",
37-
"https://*/*",
3834
"tabs",
3935
"contextMenus",
40-
"browser_action",
4136
"storage",
42-
"devtools",
4337
"windows",
4438
"activeTab",
45-
"system.display"
39+
"system.display",
40+
"scripting"
41+
],
42+
"host_permissions": [
43+
"*://*.jd.com/"
44+
],
45+
"optional_host_permissions": [
46+
"*://*/*"
4647
],
4748
"update_url": "https://clients2.google.com/service/update2/crx"
4849
}

src/pages/devtools/components/communicate/index.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -788,10 +788,11 @@ class Communicate extends React.PureComponent<CommunicateProps, CommunicateState
788788
children: this.sendDataDOM(),
789789
});
790790
}
791-
tabItems.push({
792-
key: 'openSimulation',
793-
label: '此子应用开发环境模拟',
794-
});
791+
// manifest v3 不支持unsafe-eval,簪无法模拟子应用
792+
// tabItems.push({
793+
// key: 'openSimulation',
794+
// label: '此子应用开发环境模拟',
795+
// });
795796
return (
796797
<Tabs
797798
size="small"

src/pages/popup/index.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,25 @@ interface PopupPageProps {
88
}
99

1010
class PopupPage extends React.PureComponent<PopupPageProps, PopupPageProps> {
11-
private open() {
12-
// https://developer.chrome.com/docs/extensions/reference/tabs/#examples
13-
chrome.tabs.create({
14-
url: 'simulation.html',
15-
});
16-
}
11+
// private open() {
12+
// // https://developer.chrome.com/docs/extensions/reference/tabs/#examples
13+
// chrome.tabs.create({
14+
// url: 'simulation.html',
15+
// });
16+
// }
1717

1818
public render() {
1919
return (
2020
<div className={styles.app}>
21-
<div className={styles['app-link']} onClick={() => { this.open(); }}>
21+
{/* manifest v3 不支持unsafe-eval,簪无法模拟子应用 */}
22+
{/* <div className={styles['app-link']} onClick={() => { this.open(); }}>
2223
<a>
2324
打开“子应用开发环境模拟”页面
2425
</a>
26+
</div> */}
27+
<div className={styles['app-link']}>
28+
<a>打开“子应用开发环境模拟”页面(v2版本暂不支持)</a>
2529
</div>
26-
2730
</div>
2831
);
2932
}

src/scripts/background/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab1) => {
109109
});
110110
});
111111
// 6、according to isMicroApp setting iconPath
112-
chrome.browserAction.setIcon({ path: isMicroApp ? blueIconPath : grayIconPath, tabId });
112+
chrome.action.setIcon({ path: isMicroApp ? blueIconPath : grayIconPath, tabId });
113113
});
114114
});
115115
/**
@@ -123,9 +123,9 @@ chrome.tabs.onActivated.addListener((changeInfo) => {
123123
logger.debug(`change tab value currently is ${JSON.stringify(result)}`);
124124
const data = JSON.parse(JSON.stringify(result));
125125
logger.debug('isMicroApp', data[`${changeInfo.tabId}`]);
126-
chrome.browserAction.setIcon({ path: data[`${changeInfo.tabId}`] ? blueIconPath : grayIconPath, tabId: changeInfo.tabId });
126+
chrome.action.setIcon({ path: data[`${changeInfo.tabId}`] ? blueIconPath : grayIconPath, tabId: changeInfo.tabId });
127127
} else {
128-
chrome.browserAction.setIcon({ path: grayIconPath, tabId: changeInfo.tabId });
128+
chrome.action.setIcon({ path: grayIconPath, tabId: changeInfo.tabId });
129129
}
130130
});
131131
});

src/scripts/background/open-window.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default function openDevToolsWindow(position: DevToolsPosition) {
3838
...customOptions,
3939
};
4040
if (action === 'open') {
41-
options.url = chrome.extension.getURL(
41+
options.url = chrome.runtime.getURL(
4242
`${url}#${position.slice(position.indexOf('-') + 1)}`,
4343
);
4444
chrome.windows.create(options, (win) => {

0 commit comments

Comments
 (0)