Search code examples
javascripthtmlgoogle-chrome-extension

How to get images over img referrer policy?


is there any way to hide all images, that use referrerpolicy="unsafe-url"? I know how to get images by class or id. But I didnt find referrerpolicy.

I would like to add a class to all images on a page having referrerpolicy="unsafe-url" in it.

<img referrerpolicy="unsafe-url" src='...'>

And after:

<img referrerpolicy="unsafe-url" class='hidden' src='...'>

Thanks for any hint.


Solution

  • try that but in your browser, I tested it in chrome, firefox, it's ok. Here in snippet not.

    Array.from(document.querySelectorAll('img')).forEach(el=> {
      if (el.referrerPolicy==='unsafe-url') {
        el.style.display='none';
      }
    }
    
    )
    <img referrerpolicy="unsafe-url" src='https://picsum.photos/id/20/800/600'>
    <img referrerpolicy="unsafe-url" src='https://picsum.photos/id/20/800/600'>
    <img referrerpolicy="unsafe-url" src='https://picsum.photos/id/20/800/600'>
    <img referrerpolicy="no-referrer" src='https://picsum.photos/id/20/800/600'>