title: PHP Google Push Notifications
body: <p>I've been doing research on how to use ((google push notifications)) with PHP, but there aren't many working examples/documentation out there...</p>
  
  <p>I'm trying to get this to work on an internal network, that isn't opened to the outside, over HTTP.</p>
  
  <p>I was able to get this to work over HTTPS from our outward facing domain, but the internal attempt is telling me in the Chrome Console that <code>"the API may no longer be used from insecure origins"</code>, which I found means it requires HTTPS.</p>
  
  <p>Does anyone know of a possible workaround for this, to spoof the HTTPS, or to allow it to continue over HTTP? I understand google put this in place as a preventative measure for people with malicious intent, but that's not the case here, as it'll be for private use.</p>
  
  <p>My HTML is just a button with an <code>onclick="notifyMe()"</code> event.</p>
  
  <p>Script to request permission, and function to notify:</p>
  
  <pre><code>&lt;script&gt;
  // request permission on page load
  document.addEventListener('DOMContentLoaded', function () {
    if (!Notification) {
      alert('Desktop notifications not available in your browser. Try Chromium.'); 
      return;
    }
  
    if (Notification.permission !== "granted")
      Notification.requestPermission();
  });
  
  function notifyMe() {
    if (Notification.permission !== "granted")
      Notification.requestPermission();
    else {
      var notification = new Notification('Notification title', {
        icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png',
        body: "Hey there! You've been notified!",
      });
  
      notification.onclick = function () {
        window.open("http://example.com");      
      };
  
    }
  
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>JS file with Notification Options, and permissions:</p>
  
  <pre><code>'use strict';
  
  var button = document.querySelector('button');
  var input = document.querySelector('input');
  
  var notify = function() {
    var options = {
      body: input.value,
      icon: 'icon.png',
      tag: 'foo',
      type: 'basic'
    };
    var n = new Notification('Greetings!', options);
    n.onclick = function() {
      console.log('Clicked.');
    };
    n.onclose = function() {
      console.log('Closed.');
    };
    n.onshow = function() {
      console.log('Shown.');
    };
  };
  
  button.onclick = function() {
    if (!('Notification' in window)) {
      alert('This browser does not support desktop notification');
    } else if (Notification.permission === 'granted') {
      notify();
    } else if (Notification.permission !== 'denied') {
      Notification.requestPermission(function(permission) {
        if (!('permission' in Notification)) {
          Notification.permission = permission;
        }
        if (permission === 'granted') {
          notify();
        }
      });
    }
  };
  </code></pre>