javascriptandroidgoogle-chromegoogle-chrome-osgoogle-chrome-arc

ARC packaged Android application: run JavaScript API command


I have an ARC packaged ChromeOS application and since there are some behavioral differences between ChromeOS and Android I want it to make some JavaScript API call: chrome.power.requestKeepAwake.

After the obvious step of adding "power" permission, what I've tried to do is to change contents of app_main.html:

<!DOCTYPE html>
<!-- these are the lines I've added -->
<script type="text/javascript">
chrome.power.requestKeepAwake("display");
</script>
<!-- until here --> 
<iframe src="_modules/mfaihdlpglflfgpfjcifdjdjcckigekc/main.html"></iframe>

But this lead to no changes.

I'm sure, that the request is not applied as I've tried to run the same query from Chrome console and it did the thing.

How should I manage to embed this code?


Solution

  • Actually, I've managed to solve this issue. The reason for it to happen is not that the code is applied in the wrong moment or something like this, but that the code you use in the app_main.html can't contain inline JavaScript, which is insecure.

    That said, the code should look like:

    /app_main.html:

    <!DOCTYPE html>
    <script type="text/javascript" language="javascript" src="power_request.js">
    </script>
    <iframe src="_modules/mfaihdlpglflfgpfjcifdjdjcckigekc/main.html"></iframe>
    

    /power_request.js:

    chrome.power.requestKeepAwake("display");