【发布时间】:2017-04-29 11:45:36
【问题描述】:
对不起,打扰了。 最近,我发现我的 devtools 扩展在最新版本的 Chrome 中不起作用。 它仍然可以在正常模式下工作,即打开一个选项卡,然后为该选项卡打开 devtools,一切正常。 在检查 Android WebView 时,只有 background.js 执行了一些代码,但 devtools.js 似乎根本没有被执行。
谁有同样的问题或可以指点我一个解决方案?
我的情况是,
- 启动 Chrome。
- 导航到 Chrome://inspect 页面。
- 连接 Android 设备以通过 USB 检查 WebView 以监控 http 流量。
- 然后单击“检查”链接以启动开发工具窗口。
结果是:
- 开发工具窗口已启动。
- 但是,只有 background.js 执行了一些代码,然后什么都没有发生。
Git源码下载
项目结构:
- background.js
- devtools.html
- devtools.js
- jquery-3.1.0.min.js
- manifest.json
manifest.js
{
"name": "Har Getter",
"version": "1.1",
"minimum_chrome_version": "10.0",
"description": "Har reporter",
"devtools_page": "devtools.html",
"content_scripts": [
{
"js": ["jquery-3.1.0.min.js"],
"matches": ["http://*/*", "https://*/*"]
}
],
"background": { "scripts": ["background.js"] },
"permissions": [
"http://*/*",
"https://*/*",
"tabs"
],
"manifest_version": 2
}
devtools.js
chrome.devtools.panels.create("Lucas Luo Panel",
"MyPanelIcon.png",
"Panel.html",
function(panel) {
}
);
chrome.devtools.panels.elements.createSidebarPane("Lucas Luo Sidebar",
function(sidebar) {
// sidebar initialization code here
sidebar.setObject({ some_data: "Some data to show" });
});
alert("Lucas Luo");
chrome.devtools.network.onNavigated.addListener(function (url) {
alert('starting...');
});
chrome.devtools.network.onRequestFinished.addListener(function(request) {
});
function checkRequestCount2() {
if(chrome.devtools.inspectedWindow.tabId == pcTabId) {
sendPC();
}
}
function sendPC() {
chrome.devtools.inspectedWindow.eval('performance.timing.loadEventEnd',"",function(result, exceptionInfo){
chrome.devtools.network.getHAR(function(harLog) {
clearTimeout(navTime);
var loadTimeVal = (end-start) / 1000;
endTimeVal = new Date();
alert('hello');
$.ajax({
url: 'http://localhost:4567/automation/sendHar/PC',
type: 'POST',
dataType: 'json',
data: escape(JSON.stringify(harLog)),
error: function(d) {
},
success: function(d, s) {
}
});
});
});
}
background.js
alert('background lucas luo');
devtools.html
<!doctype html>
<html>
<head>
<title>Devtools Page</title>
<script src="jquery-3.1.0.min.js" type="text/javascript"></script>
<script src="devtools.js"></script>
<script src="./background.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
最好的问候,
卢卡斯·罗
【问题讨论】:
-
请edit 成为主题的问题:包括一个完整 minimal reproducible example 重复问题。包括一个manifest.json,一些背景/内容/弹出脚本/HTML。寻求调试帮助的问题(“为什么这段代码不工作?”)必须包括:►期望的行为,►特定问题或错误和►必要的最短代码重现它在问题本身。没有明确问题陈述的问题对其他读者没有用处。请参阅:“如何创建 minimal reproducible example”、What topics can I ask about here? 和 How to Ask。
-
似乎 chrome devtools 扩展 api 在这种情况下不起作用?
标签: android google-chrome google-chrome-extension webview google-chrome-devtools