2

I create a chrome extension which offer accessibility to download any media in opened page of Facebook, including photo, video, and story. But I'm stuck when about to access/catch facebook's video story request URL that's shown up in Network tab in console, using chrome.webRequest API.

enter image description here

By excluding bytestart and byteend params from URL above, we got the full video file (with an expiration token). The <video> tag itself has src attribute like blob:https://www.facebook.com/<some_alpha_numerics_and_hyphens>.

This is what I've tried in my extension project:

permission:

"permissions": [
  "webRequest",
  "*://*/*"
],

I've tried to listen all the events available but no luck.

chrome.webRequest.onBeforeRequest.addListener(
  function(details) {
    console.log('onBeforeRequest', details.url);
  },
  {
    urls: ["<all_urls>"]
  }
);
// onBeforeSendHeaders
// onSendHeaders
// onHeadersReceived
// onAuthRequired
// onResponseStarted
// onBeforeRedirect
// onCompleted
// onErrorOccurred

I haven't tried chrome.declarativeWebRequest https://developer.chrome.com/extensions/declarativeWebRequest because it's for Beta and Dev channels only.

Is it really possible or did I have mistake in using it? Thank you in advance.

Taufik Nur Rahmanda
  • 1,862
  • 2
  • 20
  • 36
  • [Where to read console messages from background.js in a Chrome extension?](https://stackoverflow.com/q/10257301) – wOxxOm Aug 06 '20 at 03:32
  • @wOxxOm enter chrome://extensions/, then click Background link that shown below your extension item. then console window for it will open. – Taufik Nur Rahmanda Aug 06 '20 at 05:04
  • sorry, no, I mean I've checked on background console, but the log for those `webRequest` listeners not appear, meaning the event not even triggered. – Taufik Nur Rahmanda Aug 06 '20 at 05:08
  • Maybe you didn't reload the extension on chrome://extensions page after editing it? Or maybe your background script is incporrectly declared in manifest.json? Otherwise it would be a bug in Chrome. – wOxxOm Aug 06 '20 at 06:04

1 Answers1

1

I would recommend adding the "webRequestBlocking" permission to your manifest.json file.

According to the documentation the callback uses a blocking event handler that requires the "webRequest" as well as the "webRequestBlocking" permission in order to work.

Reference: https://developer.chrome.com/extensions/webRequest#examples

jasonandmonte
  • 1,869
  • 2
  • 15
  • 24