Intercept Chrome translating with js - google-chrome-extension

I have chrome extension and auto translate option on Chrome is changing some dates on page, which cause some errors while data processing.
Is it possible to turn of translate of the page, from the content script?
I have tried with appending the element with also tried to add class "notranslate" to .

Related

Python: Scrape JavaScript generated content

I'm trying to do a web scraping because I need to grab text from a web page, but the text is generated by JavaScript. I can't use Selenium to simulate the browser because there's too much text to be generated and it will make it crash. I can't do it with requests, because the requested URL doesn't return the desired text due to JavaScript, but if I paste the URL in Chrome it gives me what I need. I have not managed to get the expected results in python and I need some help.

Using jquery for parsing causes image network traffic in Chrome extension?

I'm writing an extension that scrapes web pages using jquery. After a while I start getting net errors saying resources not available and errors in the console loading images in the pages I'm scraping. I thought it might be $.get() loading it as html somehow, but it still happens when I use a raw XMLHttpRequest and it appears even when I call $(text) with static text.
Looking in the application tab of my background page I can see that there are images, even though they don't exist in the html. For example run this in the console of any extension background page:
$('<div>Hello, world!<img src="https://www.gravatar.com/avatar/fdc806d0a8834e57b2d9309849dea8cd"/></div>')
And you can see the image was loaded on the Application tab in dev tools, though it isn't in the html of the page when inspected and but it's visible on the network tab:
I assume that jquery is creating dom elements to use the browser's capabilities for finding elements, and that chrome is happily pre-fetching that image even though the element isn't on the page and the page will never be visible anyway, but it is causing me errors besides the extra network traffic.
I've tried disabling 'precache' in chrome://flags but that didn't work. For now I'm replacing <img with <noimg which seems to work but is not ideal:
$(text.replace(/<img /g, '<noimg '))
Is there a way to keep this from happening? Is there another library besides jQuery (like cheerio in node) that wouldn't actually create dom objects?
Use the built-in DOMParser to parse the HTML into a detached document, then use jQuery on that document object:
var doc = new DOMParser().parseFromString(yourHTMLstring, 'text/html');
$('.some.selector', doc).attr('foo', 'bar');
In case there may be relative links in the HTML, add a base element explicitly:
$(doc.head).append('<base href="' + realFullURL + '">')

Browser plugin/extension/addon to see id of all elements at once

Despite extensive Google search I haven't been able to find what I was looking for, so I'm hoping experienced SO users will have an answer.
I am looking for a Firefox or Chrome plugin that can automatically display elements' id attribute value inside an overlay on top of the actual elements. For instance:
The idea is to be able to have a quick snapshot of what id attributes are used within a page and where, instead of having to go through the entire page manually with tools such as Firebug or Firefox/Chrome's DOM inspectors (which only allow you to see elements one by one, not have a full picture).
Does anybody know a Firefox / Chrome plugin that can do that?
The "Web Developer" extension for Firefox / Chrome includes this feature. The option can be toggled by clicking on "Information -> Display Anchors".
https://addons.mozilla.org/en-US/firefox/addon/web-developer/
https://chrome.google.com/webstore/detail/web-developer/bfbameneiokkgbdmiekhjnmfkcnldhhm
In Firefox
In Chrome
Result
Instead of installing an extra extension, you could also enter $$('[id]') in the console, which results in a list of all elements with an "id" attribute.

How to edit current viewed page html source using Chrome extension?

I want to build a chrome extension that hides a specific div (with id) from page on load.
I want to know how to edit the source?
Just use jQuery, and write this code in your content script:
$("#you_div_id").hide();
It's so easy:)

Override downloading a file type with Chrome Extensions

I'm trying to build a chrome extension that overrides a download of a file and displays it in the browser. For example if you click on a link to a '.csv' file I'd like it to render in the browser instead of downloading it.
Chrome already does it for PDF's types and the Xml Tree extension also does exactly that for xml files.
So it should be possible, just not sure how to go about catching that event?
An implementation along the lines indicated by in the previous answers and specifically designed for CSV files can be found in this extension of mine on github:
https://github.com/rgrp/chrome-csv-viewer
Furthermore, with the new(ish) chrome webrequest API a direct approach is also now possible along the following lines:
Listen to onBeforeRequest (this has to be in a background script - see background.js)
Check if this is a CSV file (mimetype or file extension)
If so cancel the request and then display the data using xhr
A working version of this can be found in a branch of that extension: https://github.com/rgrp/chrome-csv-viewer/tree/4-webrequest-intercept
You could always look at the XML Tree code :).
If you only need to work with links, and not opening files from the address bar or File > Open, you could build a content script that adds a click event listener to every link.
In the event listener function:
Add e.preventDefault() in the first line to prevent the browser 'following' the link.
Using the link href value, get the data with XMLHttpRequest.
In the XMLHttpRequest callback, open a new tab and render content accordingly.
Obviously, in many ways, this is not a great solution:
you want 'normal' links to be handled as usual by the browser
how can you tell if a text file contains comma-separated values (for example) except by looking at the file extension which, of course, may not be reliable?
Are you specifically thinking of .csv files -- and/or other specific types of content?

Resources