Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the element from a view-source: page?

I have made a small Chrome extension which has a click event listener that captures the element and then it gives the xpath.

But this is not capturing anything on a view-source: page.

Is there any way by which I can capture the element from view-source: page in JavaScript?

I am trying with this code on my content page:

document.addEventListener('click', function xyz(e){
  e.preventDefault();
  //alert(e);
  var target = e.target || event.srcElement;
  var attributes = Array.prototype.slice.call(target.attributes).map(function(i) {
    return [String(i.name)+": "+String(i.value)]
  })
  alert(attributes);
  prompt("xpath1 :",getPathTo(target));
  chrome.runtime.sendMessage({method:"captureElement",data:attributes});   
},true)
like image 782
Abhishek Tripathi Avatar asked Nov 26 '25 22:11

Abhishek Tripathi


1 Answers

There is nothing you can do, you can't interact with those pages.

Extensions cannot get access to view-source: protocol pages (it's not a supported scheme), so you can't inject a content script in them at all, even with "<all_urls>" filter.

like image 147
Xan Avatar answered Nov 28 '25 13:11

Xan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!