0

We want a Chrome extension with this policy: http://www.chromium.org/administrators/configuring-policy-for-extensions So we can hide the 'welcome' page on our intern Network. And regular users (from Chrome web store) see the 'welcome' page when they installed this Chrome extension.

The first Background.js code work OK, here it shows the 'welcome page' when the user install this extension for the first time. I upgrade the code to 'new background', but the code doesn't do the task of hiding the 'welcome page' with the network 'policy' registry. Any idea on how to fix this issue? Or what JavaScript code is missing?

This is our code: Background.js

chrome.storage.local.get(['firstRun'], function(chromeset){
if ((chromeset["firstRun"]!="false") && (chromeset["firstRun"]!=false)){
  chrome.tabs.create({url: "http://www.google.com", selected:true})
  chrome.storage.local.set({"firstRun": "false"});
}
});

manifest.js

  ...

"permissions": [
    "bookmarks"
  ],
  "storage": {
    "managed_schema": "schema.json"
  }
}

schema.json

{
  "type": "object",
  "properties": {
    "HideFirstRunPage": {
      "title": "Hide the first welcome page",
      "description": "Configures App to show not the first welcome page when you install this extension.",
      "type": "boolean"
    }
  }
}

New background.js

var HideFirstRunPage = false;

if (require("info").platform == "chromium" && "managed" in chrome.storage)
 {
        chrome.storage.managed.get('HideFirstRunPage', function (data) {            
                var thenewvalue = data.HideFirstRunPage;
                if(thenewvalue == true){
                chrome.storage.local.set({"firstRun": "false"});
                } else{
                initwelcome()
                }
            }); 
} else{
initwelcome()
}    


function initwelcome(){
    // new user? Then open this google.com page
    chrome.storage.local.get(['firstRun'], function(chromeset){
    if ((chromeset["firstRun"]!="false") && (chromeset["firstRun"]!=false)){
    chrome.tabs.create({url: "https://www.google.com", selected:true})
    chrome.storage.local.set({"firstRun": "false"});
    });
 }

 document.addEventListener('DOMContentLoaded', function () {initwelcome()}
user1731468
  • 864
  • 2
  • 9
  • 30
  • "It doesn't work" is not very descriptive, and the code is incomplete (nothing calls `initwelcome`). Please fix your question. – Xan Jan 14 '16 at 14:51
  • @Xan updated. Need just a simple working sample of the Chrome 'policy' to hide the 'welcome page' for in our network. And in the Chrome web store it must show that regular 'welcome page'. – user1731468 Jan 14 '16 at 14:58
  • Your code has a standard "let's modify a global variable with an asynchronous function" error. Basically you need to call `initwelcome()` from inside the `managed.get` callback for it to have a proper order of execution. – Xan Jan 14 '16 at 15:00
  • @Xan that is not the same question or duplicate! It's about the Chrome.storage.managed API – user1731468 Jan 14 '16 at 15:01
  • So far it _is_. Maybe it's not the only problem, but first fix that. – Xan Jan 14 '16 at 15:03
  • @Xan what line? The first background JavaScript works just fine. – user1731468 Jan 14 '16 at 15:09
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/100680/discussion-between-xan-and-user1731468). – Xan Jan 14 '16 at 15:18

0 Answers0