mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-07-03 12:06:31 +02:00
parent
f02246128e
commit
52e44e0eb2
4 changed files with 44 additions and 15 deletions
|
@ -8,13 +8,13 @@
|
|||
<div id="top">
|
||||
<h1>top Test</h1>
|
||||
<img class="display"><br>
|
||||
Hash: <span class="hash"></span>
|
||||
Hash: <span class="hash"></span> (isPointInPath: <span class="isPointInPath"></span>)
|
||||
<button>refresh</button>
|
||||
</div>
|
||||
<div id="iframe">
|
||||
<h1>iFrame Test. Thanks to DocumentRoot.</h1>
|
||||
<img class="display"><br>
|
||||
Hash: <span class="hash"></span>
|
||||
Hash: <span class="hash"></span> (isPointInPath: <span class="isPointInPath"></span>)
|
||||
<iframe sandbox="allow-same-origin" style="display:none"></iframe>
|
||||
<button>refresh</button>
|
||||
</div>
|
||||
|
@ -22,7 +22,7 @@
|
|||
<div id="iframe2">
|
||||
<h1>iFrame Test 2 - with URL</h1>
|
||||
<img class="display"><br>
|
||||
Hash: <span class="hash"></span>
|
||||
Hash: <span class="hash"></span> (isPointInPath: <span class="isPointInPath"></span>)
|
||||
<iframe src="?" sandbox="allow-same-origin" style="display:none"></iframe>
|
||||
<button>refresh</button>
|
||||
</div>
|
||||
|
@ -30,7 +30,7 @@
|
|||
<div id="iframe3">
|
||||
<h1>iFrame Test 3 - violating SOP</h1>
|
||||
<img class="display"><br>
|
||||
Hash: <span class="hash"></span>
|
||||
Hash: <span class="hash"></span> (isPointInPath: <span class="isPointInPath"></span>)
|
||||
<iframe src="http://example.org" style="display:none"></iframe>
|
||||
<button>refresh</button>
|
||||
</div>
|
||||
|
|
27
test/test.js
27
test/test.js
|
@ -2,7 +2,7 @@
|
|||
(function(){
|
||||
"use strict";
|
||||
|
||||
function show(container, url){
|
||||
function show(container, {url, isPointInPath}){
|
||||
var display = container.querySelector(".display");
|
||||
display.src = url;
|
||||
display.title = url;
|
||||
|
@ -16,6 +16,7 @@
|
|||
return "0".repeat(8 - chunk.length) + chunk;
|
||||
}).join("");
|
||||
});
|
||||
container.querySelector(".isPointInPath").textContent = isPointInPath;
|
||||
}
|
||||
|
||||
if (location.search !== "?notInitial"){
|
||||
|
@ -64,14 +65,29 @@ function draw(canvas){
|
|||
return ctx;
|
||||
}
|
||||
|
||||
function getIsPointInPath(ctx){
|
||||
"use strict";
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(20, 19);
|
||||
ctx.lineTo(40, 19);
|
||||
ctx.lineTo(30, 30);
|
||||
ctx.closePath();
|
||||
ctx.stroke();
|
||||
|
||||
return ctx.isPointInPath(30, 19);
|
||||
}
|
||||
|
||||
function topTest(){
|
||||
"use strict";
|
||||
|
||||
// create window canvas
|
||||
var canvas = document.createElement("canvas");
|
||||
// draw image in window canvas
|
||||
draw(canvas);
|
||||
return canvas.toDataURL();
|
||||
var ctx = draw(canvas);
|
||||
return {
|
||||
url: canvas.toDataURL(),
|
||||
isPointInPath: getIsPointInPath(ctx)
|
||||
};
|
||||
}
|
||||
|
||||
function iframeTest(iframe){
|
||||
|
@ -92,5 +108,8 @@ function iframeTest(iframe){
|
|||
// copy image from window canvas to iframe ctx
|
||||
iframe_ctx.drawImage(canvas, 0, 0);
|
||||
|
||||
return iframe_canvas.toDataURL();
|
||||
return {
|
||||
url: iframe_canvas.toDataURL(),
|
||||
isPointInPath: getIsPointInPath(iframe_ctx)
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue