Home | History | Annotate | Download | only in basic_auth_extension
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Script that automatically listend for an onAuthRequired request and sends
      6 // hardcoded credentials back.
      7 
      8 var gPendingCallbacks = [];
      9 var bkg = chrome.extension.getBackgroundPage();
     10 
     11 bkg.console.log("Listening")
     12 chrome.webRequest.onAuthRequired.addListener(handleAuthRequest,
     13                                              {urls: ["<all_urls>"]},
     14                                              ["asyncBlocking"]);
     15 
     16 function processPendingCallbacks() {
     17   bkg.console.log("Calling back with credentials");
     18   var callback = gPendingCallbacks.pop();
     19   callback({authCredentials: {username: 'admin', password: 'password'}});
     20 }
     21 
     22 function handleAuthRequest(details, callback) {
     23   gPendingCallbacks.push(callback);
     24   processPendingCallbacks();
     25 }
     26 
     27 
     28