Issue with launching Chrome Web App

I am new to Chrome Web App programming. I want a simple WebApp that is separate from my Chrome / Chromium (no tabs). It should show the external website in the body.

So here is my configuration:

manifest.json

{
  "name": "Hello World!",
  "description": "My first Chrome App.",
  "version": "0.1",
  "manifest_version": 2,
  "permissions": [ "webview" ],
  "icons": {
    "128": "icon_128.png"
  },
  "app": {
    "background": {
      "scripts": ["background.js"]
    }
  }
}

background.js

chrome.app.runtime.onLaunched.addListener(function() {
  chrome.app.window.create('window.html', {
    bounds: {
      'width': 400,
      'height': 600
    }
  });
});

window.html:

<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
    <webview style="width: 100%; height: 100%;" src="http://www.google.de"></webview>
  </body>
</html>

I tried a window like this (this shows Chrome for the daemon): enter image description here

But I got the following:

enter image description here

Therefore, the height in webview is incorrect. When I set the height (for example) to 192px, it shows the correct size. But 100% does not work ...

+4
source share
5 answers

I asked François Beaufort (Chromium engineer atm) on Google+. Hey replayed:

chromium window.onresize - : https://github.com/GoogleChrome/chrome-app-samples/blob/master/samples/webview-samples/browser/browser.js

Chrome.

manifest.json:

{
  "name": "Hello World!",
  "description": "My first Chrome App.",
  "version": "0.1",
  "manifest_version": 2,
  "permissions": [ "webview" ],
  "icons": {
    "128": "icon_128.png"
  },
  "app": {
    "background": {
      "scripts": ["background.js"]
    }
  }
}

background.js

chrome.app.runtime.onLaunched.addListener(function() {
  chrome.app.window.create('window.html', {
    bounds: {
      'width': 1050,
      'height': 700
    }
  });
});

window.html

<!DOCTYPE html>
<html>
  <head>
    <style type="text/css">
      body {
        margin: 0px;
      }
    </style>
  </head>
  <body>
    <webview src='http://www.google.de' id="xx"></webview>
    <script src="main.js"></script>
  </body>
</html>

main.js( : D)

function updateWebviews() {
  var webview = document.querySelector("webview");
  webview.style.height = document.documentElement.clientHeight + "px";
  webview.style.width = document.documentElement.clientWidth + "px";
};

onload = updateWebviews;
window.onresize = updateWebviews;

, . - -: enter image description here

Edit:

git GitHub SourceCode: https://github.com/StefMa/ChromeAppWebsite

+8

( HTML ):

webview {
   display: flex;
   height: 100vh;
}
+6

, , :

<webview src="https://github.com" style="width: 100%; height: 100%; display: inline-block; position: absolute; top: 0; bottom: 0; left: 0; right: 0;"></webview>
+2
source

This can happen because you are using relative height and width with <!DOCTYPE html>. See this answer for an explanation.

Instead of using 100%, you can try to specify the width and height in pixels.

<webview style="display:block; width:400px; height:600px;" src="http://www.google.de"></webview>
+1
source

Add this to styles.css

webview{
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
0
source

All Articles