Skip to content

Instantly share code, notes, and snippets.

@kortina
Created March 31, 2020 02:47
Show Gist options
  • Save kortina/8cbba68393606d1b5bfc3aa0c13eea36 to your computer and use it in GitHub Desktop.
Save kortina/8cbba68393606d1b5bfc3aa0c13eea36 to your computer and use it in GitHub Desktop.
Pocket Bookmarklet That Avoids Cookie Errors
// Was getting the following error on many sites with the 'official' Pocket Bookmarklet
// ( available at https://getpocket.com/add/?ep=1 )
//
// VM171:1 Refused to load the script 'https://getpocket.com/b/r4.js?h=qqualnjcokmhwrrxefqvqbftooidhfpmommvsfsecblmtqugvmwf46684f1f0&u=https%3A%2F%2Fwww.linkedin.com%2Fpulse%2Fmechanics-war-economy-ray-dalio%2F&t=(6)%20The%20Mechanics%20of%20the%20War%20Economy%20%7C%20LinkedIn'
// because it violates the following Content Security Policy directive:
// "script-src 'report-sample' 'sha256-6gLjSWp3GRKZCUFvRX5aGHtECD1wVRgJOJp7r0ZQjV0=' 'unsafe-inline' s.c.lnkd.licdn.com static-fstl.licdn.com static-src.linkedin.com https://www.linkedin.com/voyager/service-worker-push.js s.c.exp1.licdn.com s.c.exp2.licdn.com static-lcdn.licdn.com s.c.lcdn.licdn.com https://www.linkedin.com/sc/ https://www.linkedin.com/scds/ https://qprod.www.linkedin.com/sc/ https://www.linkedin.com/sw.js https://www.linkedin.com/voyager/abp-detection.js https://snap.licdn.com/li.lms-analytics/insight.min.js https://platform.linkedin.com/js/analytics.js https://platform-akam.linkedin.com/js/analytics.js https://platform-ecst.linkedin.com/js/analytics.js https://platform-azur.linkedin.com/js/analytics.js https://platform.linkedin.com/litms/utag/ https://platform-akam.linkedin.com/litms/utag/ https://platform-ecst.linkedin.com/litms/utag/ https://platform-azur.linkedin.com/litms/utag/ https://platform.linkedin.com/litms/vendor/ https://platform-akam.linkedin.com/litms/vendor/ https://platform-ecst.linkedin.com/litms/vendor/ https://platform-azur.linkedin.com/litms/vendor/ static.licdn.com static-exp1.licdn.com static-exp2.licdn.com static-exp3.licdn.com".
// Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
//
// This uses the page instructions at:
// https://help.getpocket.com/article/1007-saving-to-pocket-manually
// to open a small window to
// https://getpocket.com/edit
// and pass the current page as the `url` query string param (guessed from the pocket API)
// When adding as a Chrome Bookmarklet, make sure to prefix with:
// javascript:
(function(){open('https://getpocket.com/edit?url='+encodeURIComponent(document.location.href),
'pocket_add_target',
'height=300,width=500,menubar=no,location=no,resizable=no');
})()
//
// Reference on window.open
// https://developer.mozilla.org/en-US/docs/Web/API/Window/open
@kortina
Copy link
Author

kortina commented Mar 31, 2020

Here is what it looks like when you click it:

image

It pops open a new small window instead of injecting into the current page, which can cause a bunch of security / cookie issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment