0

I've been trying to write a chrome extension that tracks all of a users scrolling across their browser window and sends this data to chrome.storage.sync

I've been unsuccessful in seeing any data recorded in chrome.storage and am not sure if this because of the scroller.js script I have included below or if I have not directed to .storage correctly.

I haven't been able to find a solution from other answers posted here so any help would be greatly appreciated!

manifest.json

{
"manifest_version": 2,
"name": "Caressing the Silver Rectangle",
"description": "Measures Jesse Bowling's distance scrolled in pixels on Google Chrome",
"version": "1.0",
"content_scripts": [
    {
        "matches": [
            "<all_urls>"
        ],
        "js": [
            "scroller.js"
        ],
        "run_at": "document_start"
    }
],

"background": [
{ "scripts": ["https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"]
               }


],

"browser_action": {
    "default_icon":"icon.png",
    "default_title": "Caressing the Silver Rectangle",
    "default_popup": "popup.html"
},
"permissions": [
    "activeTab",
    "<all_urls>",
    "tabs",
    "storage"
]
} 

scroller.js

/*jslint devel: true */

var totalScroll;
var lastKnownScrollPos = 0;

window.addEventListener("scroll", function () {
"use strict";
console.log(lastKnownScrollPos);
totalScroll += Math.abs(window.scrollY - lastKnownScrollPos);
lastKnownScrollPos = window.scrollY;
chrome.storage.local.sync({ scroll: totalScroll });
});
Blasanka
  • 21,001
  • 12
  • 102
  • 104
Sean
  • 21
  • 7
  • 1
    1. Remove the background page declaration as you're not using it and it's incorrect anyway (only locally stored scripts may be used) 2. There's no chrome.storage.local.sync as you can see in the documentation and examples. – wOxxOm Apr 14 '17 at 05:50
  • 1
    What *exactly* is shown in the [various appropriate consoles for your extension](http://stackoverflow.com/a/38920982/3773011) when you load and execute your extension? Your extension should be generating errors, which would greatly help you to identify your problem. Checking the consoles for errors should be one of the *first* things you do when your code does not do what you expect. – Makyen Apr 14 '17 at 15:58
  • @wOxxOm thanks! I have removed the background script, I wondered if i needed that at all. Woops! didn't see the **chrome.storage.local.sync** error at all, i have changed this to **chrome.storage.local** but am still not seeing any info logged in the chrome developer tools console. – Sean Apr 15 '17 at 05:48
  • thanks @mayken ! very helpful :) checked consoles and found is had begun logging! – Sean Apr 15 '17 at 06:25

1 Answers1

0

There is no method .sync.

To put a data into the storage you should use:

chrome.storage.local.set({scroll: totalScroll})

Consider, what kind of storage do you need:
- local storage is used to keep a data locally, inside a chrome instance
- sync storage helps to sync data between browsers

The chrome.storage.sync and chrome.storage.local implements StorageArea interface. Its methods are described here

Denis L
  • 3,209
  • 1
  • 25
  • 37
  • thank you @deliaz! this seemed to do the trick! getting the occasional errors in console on some pages but for the most its logging! thanks for directing me to **storage area** that helped to know – Sean Apr 15 '17 at 06:26