nulll
nulll

Reputation: 1603

Chrome extension can't modify the dom of a single page

I'm playing around with chrome extensions. I've made a simple extension that deletes all the body content, just for learning purpose.

Works fine with almost all sites (facebook, yahoo, google) but somehow is not working here https://login.live.com/

This is my code:

manifest.json

{
  "name": "test",
  "description": "test",
  "version": "0.1",
  "manifest_version": 2,
  "permissions": [
    "storage"
  ],  
  "content_scripts": [{
    "matches": ["<all_urls>"],
    "js": ["content_script.js"],   
    "run_at": "document_end"
  }]  
}

content_script.js

document.body.innerHTML = '';

Why the extension is not effective on that page? I'm missing something about chrome extensions or Microsoft implements some security measures?

Upvotes: 0

Views: 242

Answers (1)

Xan
Xan

Reputation: 77571

DOM can be added after your document_end-timed script executes.

Quoting Chrome docs:

In the case of "document_end", the files are injected immediately after the DOM is complete, but before subresources like images and frames have loaded.

So it is possible that your script executes before page's own $(document).ready(...) or equivalent, that still adds some content.

Upvotes: 1

Related Questions