我正在尝试制作一个Chrome应用,以显示webview的实时html源代码。
的index.html
<!doctype html>
<html>
<head>
<script type="text/javascript" src="popup.js"></script>
</head>
<body>
<webview id="wa_webview" src="https://www.google.com/" autosize="on"></webview>
<br>
<h2 id="heading">Source Code</h2>
<p id="demo"></p>
</body>
</html>
popup.js
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('popup.html', {
'id': 'window_launcher',
'outerBounds': {
'width': 1200,
'height': 900
}
});
});
document.addEventListener('DOMContentLoaded', function(event) {
let view = document.getElementById('wa_webview');
view.addContentScripts([{
name: 'contentScript',
matches: ['*://google.com/*'],
}]);
view.executeScript(
{code: 'document.documentElement.innerHTML'},
function(results) {
var source = results[0];
document.getElementById('demo').innerHTML = source;
});
});