-1

I want to create a Chrome extension that runs through a forum and copies all the links to each post on a particular page to a Google Spreadsheet. I can't find much on using Google Apps Script in a Chrome Extension - does anyone have any resources or can you point me in the right direction? Thanks in advance!

bcarroll
  • 49
  • 1
  • 5
  • 1
    possible duplicate of [Can I execute Google Apps Script code from a Chrome extension?](http://stackoverflow.com/questions/18404922/can-i-execute-google-apps-script-code-from-a-chrome-extension) – HDCerberus May 13 '15 at 18:31

2 Answers2

2

You can absolutely launch an Apps Script published as a web app from a chrome extension. Here is a simple example. This extension will ask you to launch a script every time you open www.google.com. Annoying, but I tried to make it as simple as possible.

Background.js

// Handle requests for script launch
chrome.runtime.onMessage.addListener(function(request) {
    if (request.type === 'launch_script') {
        chrome.tabs.create({
            url: 'https://script.google.com/a/macros/YOUR SCRIPT URL/exec',
            active: false
        }, function(tab) {
            // After the tab has been created, open a window to inject the tab
            chrome.windows.create({
                tabId: tab.id,
                type: 'popup',
                focused: true
                // incognito, top, left, ...
            });
        });
    }
});

manifest.json

{
  "name": "Script Launch Test",
  "version": "1.0",
  "manifest_version": 2,
  "background": {
      "scripts": ["background.js"],
      "persistent": false
  },
  "content_scripts": [{
      "matches": ["https://www.google.com/*"],
      "js": ["open-dialog.js"]
  }]
}

open-dialog.js

if (confirm('Launch Script?'))
    chrome.runtime.sendMessage({type:'launch_script'});
Spencer Easton
  • 5,642
  • 1
  • 16
  • 25
1

The basic answer is yes, this is possible. This answer to a similar question includes a minimal working example.

However, given the restrictions GAS works under, I would instead consider skipping the Apps script part entirely, and instead using the Sheets APIs to access the content directly.

Community
  • 1
  • 1
HDCerberus
  • 2,113
  • 4
  • 20
  • 36