I am attempting to develop a web extension that protects people against browser fingerprinting and I am working on the canvas API at the moment. I need to 'spoof' or 'fake' the image data that is returned from the following methods to prevent canvas fingerprinting:
HTMLCanvasElement.toDataURL() - toDataURL() Documentation
HTMLCanvasElement.toBlob() - toBlob() Documentation
CanvasRenderingContext2D.getImageData() - getImageData() Documentation
And possible more ... But lets start with these. I am using javascript prototypes to override methods. toDataURL() returns a fake output which is good however toBlob() and getImageData() both still return the same value which is also the real output, not what I want :(
The repository is on github.
This canvas.js file contains my code that attempts to add 1 to every byte in the array which is in RGBA format. Yes I know this is terrible, its only for testing. I will use random numbers for the real thing but at the moment I am just trying to get it to return a value that is different from the default so that a hash of the pixel data or image data would be different.
Any ideas??? If you need additional info or do not understand somethning please ask me or let me know. Thanks ...
Related
I'm getting one base64 string from API response and other one I'm converted image (which is in test data file) to base64 using cypress readfile method.
When I'm using below command the assertion is failing because there is tracking number difference which will be always new with every call.
And I'm getting 2 different base64.
//This base64 is from API response
var base64FromAPI =
res.body.completedShipments[0].completedPackages[0].documents[0].image;
//Image is picked from Test Data file and converts to base64
cy.readFile(`cypress/e2e/Testdata/Canada Post 02StoreId.pdf`, "base64").should(
"eq",
base64FromAPI
);
Because there is tracking number on the label(image) which will be generated from API response is always different.
Is there any other way to compare base64 strings and to ignore some % of difference while comparing in cypress or javascript.
Or is there any other way to do this.
Thanks in advance.
Essentially you can't do this at the base64 level. The differences in a raw bitstream like base64 are totally meaningless. The differences can only become apparent through rendering that image. Actually, what you need to do is pretty complex! I'm assuming it's not possible or a good idea in your use case to change away from having the server add the text to the image, to for example, using DOM to overlay it instead.
If that's the case, the only thing you could do is utilise visual regression testing. With this, you can set a threshold on which a % similarity is defined.
Since the base64 comes from the API. This would probably mean also having test code that injects an img tag with the base64 as the source, so you can allow the visual snapshot to take place.
This works at the level of image analysis rather than on the actual bitstream. Internally it will render and compare the images.
Another way I can think of, though this is quite complex and I wouldn't pursue it unless the above did not work is to:
Use image manipulation libraries to load the base64 into an actual rendered image in memory.
Try to cut away/crop the superimposed text using image manipulation libraries in order to reliably remove areas of difference.
Base 64 that.
Compare that to a known stable base64 of the "rest" of the image.
There was an interesting discussion over here on StackOverflow, and in some ways this question is a followup. I've also asked a similar question in the past, but I feel this is more generally a question about object URLs.
There have been a number of times where I would like to implement a streaming version of a ".src" for image or video elements in JS, perhaps from a stream of bytes. Unfortunately, I only see two main options that are more controllable by JS:
Create a Blob and then use URL.createObjectURL(). Unfortunately, this seems to be static - but perhaps there is a way to mutate the contents?
Create a MediaSource. However, this only works for video and is much pickier than just using a video element, which is really the level of support I need.
Any thoughts on how I can create some type of streaming object URL? And/or if not, does anybody know why JS hasn't implemented this type of streaming long, long ago?
There have been a number of times where I would like to implement a streaming version of a ".src" for image or video elements in JS, perhaps from a stream of bytes.
Use a Service Worker to respond with a Response with a ReadableStream as the body.
but I feel this is more generally a question about object URLs.
Object URLs really only represent immutable Blobs. The MediaStream object URL is a special case, not really applicable here, and a deprecated API as srcObject exists for media elements these days.
Create a Blob and then use URL.createObjectURL(). Unfortunately, this seems to be static - but perhaps there is a way to mutate the contents?
No, Blobs are immutable.
Create a MediaSource. However, this only works for video...
... or audio.
I'm adding a new function to my node express server that will allow me to upload a drivers ELD daily log and get from that image / pdf the time driven, start time, end time, lunch, etc..
I've looking into converting the pdf into a csv / json / html, but the issue there is that it's an unlabeled mess. So I am figuring that trying to somehow read and create a chart similar to the chart already on the eld log.
ie. Reading it would be segmented by say 15 minutes, or however many pixels.
IF line exists in segment call proceed and log data ELSE check segments "SB" "D" "ON" then recursively call
In the example shown above, this driver went on duty at 6:45am.
The files are provided in a pdf format, and I am having issues extracting the data and have it be useful / labeled.
UPDATE: Thinking about it a bit more, this solution might be pretty resource costly, especially if done on the server end, ie. chopping up the image / leaving it in a buffer and reading off it... Maybe it would be better to just try and make sense of the garbage parsing from pdf to something else...
UPDATE 2: I may try and use Tesseractocr depending on how it outputs data.
Using on a page like this:
I think the term you're looking for is OCR (optical character recognition). That's the name of the technology for converting text on images into actual text to work with. Once you have that, decoding the text should be easy if it's in a standard format. There are plenty of OCR libraries for Node: https://www.npmjs.com/search?q=OCR No need to reinvent the wheel and try to build your own OCR system :)
If I drag an image to google and search, I get results of other images that are similar.
I'd like javascript or C++ or C# code to send an arbitrary image and get back the top 10 similar images along with the labels (if any) that are associated with each.
I'm even ok with pre-uploading "my" image so it accessible via url. So I'd like to do:
customsearch.google.com?myurl=123.com/snap.jpg&limit=10
And i'd like to get back:
results:[
{"a.com/2003nissan.jpg":["nissan","red","2003","car"]},
{"cd.com/maxima_2001.jpg":["Maxima","2001","dealer","used"]},
{"b.com/fordf150.jpg":["f-150","truck","2007","driver"]}
]
That is of course the simplified example. I'm fine with wading through all the api and getting the results in any format, but what I need to know is
Is this possible?
If so, what basic steps do I take (eg, get an api
key, load X.js, ?)
Any example or tutorial would be greatly appreciated.
Finally, if Bing, or anything else, can do the same, I'm not prejudiced.
While not a webservice (yet) OverFeat is a fully trained deep neural network. It's available for free as a command line app. You just pass it the image, and it tells you the top 5 labels it thinks are related. It was trained on a database of I think 1 million images, and it has 1000 different labels that it chooses from.
It even has an example of running it with a webcam. I'll be trying it out soon, but I do believe this will give pretty good results.
I need to download a BMP with JavaScript and render it to the screen, in Internet Explorer. First off, yes, I know this is insane, I'm not going to get into why, let's just accept for a moment that img src is not working because of security constraints, but an ajax request with the proper authentication in the post will pull back the image. This example bypasses all the security for the sake of simplicity and just proves we can render something.
The best idea I could come up with was to fetch the stream via ajax, decode the bitmap, and then render it with canvas. Internet Explorer obviously doesn't support canvas, but luckily Google provided a wrapper to SVG called excanvas that I can use for that.
My code (drawing code appears to work, bmp decoding not so much)
http://gist.github.com/614328
Future support for other images besides BMP is plausable, and because of how the canvas works it's easiest to draw pixels in RGBA. Texture2D is essentially the wrapper class for an RGBA byte array, plus the drawing code. ByteStream makes it a bit easier on the eyes dealing with the byte array, and BitmapDecoder contains the method to translate the BGR format to RGBA texture2d for drawing.
Is it possible the bytes are getting mis-translated along the way or is there something the matter with my decoding logic?
FYI, I got the file spec from wikipedia:
http://en.wikipedia.org/wiki/BMP_file_format#Bitmap_Information_.28DIB_header.29
Any idea what's going on in the decoding logic or drawing logic that's causing my BMP to draw incorrectly?
XMLHttpRequest (aka AJAX) was primarily designed for text content, so it's possible that binary data (especially null characters) aren't translated correctly. The first check would be to compare the size of retrieved data with the actual file size.
At least on Firefox, there seems to be a way to specifically retrieve binary data, as described here: Handling binary data.
Here's a much easier (and vastly more performant) approach: base64 encode the BMP data (you can do this either on the server or the client) and then embed it in the page using a data URI:
<script type="text/javascript">
function fetchBmp() {
$.get('http://localhost:3168/experimental/imgrender/beta.bmp', function (data) {
var base64Data = $.base64.encode(data); // *
$('#my-image').attr('src', 'data:image/bmp;base64,' + base64Data);
});
}
// * Lots of plugins for this, e.g. http://github.com/carlo/jquery-base64
</script>
<img id="my-image" />
All modern browsers support data URIs (including IE8 and up--for IE7 workarounds exist) as well as the BMP format.
As casablanca points out, there may be issues with loading binary data via Ajax, so you may have to google around for workarounds.
The fix was a combination of two things
a bit of VBScript to read the raw bytes of responseBody
decoding the byte data properly, each pixel is not padded as the wikipedia article suggests, it's actually each scanline that is padded to dword size.
Working code:
http://gist.github.com/616240