Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8f08aea
Added RequestPayment function check recipe
Jun 9, 2017
2ee9842
Added PaymentRequest.js recipe
Jun 9, 2017
84e12a8
Merge branch 'master' of https://github.com/MicrosoftEdge/css-usage
Jul 31, 2017
e795a5b
Added test script for fiddler proxy
Oct 30, 2017
f9cee4b
adding a fiddler script for debugging
Oct 31, 2017
a8d1655
First pass of pointer events recipe.
jevery23 Nov 1, 2017
b1d070f
Second pass with pointer events and touch events listening.
jevery23 Nov 1, 2017
8dd32ed
Getting pointer events and touch events listening checks test ready f…
jevery23 Nov 2, 2017
367bc7f
Remove unnecessary recipes and tests to make crawl faster.
jevery23 Nov 2, 2017
598ac29
Merge in master.
jevery23 Nov 2, 2017
f5bcd8d
Delete VS files that should not have been committed.
jevery23 Nov 2, 2017
88430ad
Adding some more stuff to get-element fiddler script
Nov 2, 2017
9c5ebcd
Updates to recipe in response to PR.
jevery23 Nov 2, 2017
105bcc7
Update to make recipe script more efficient.
jevery23 Nov 2, 2017
8692352
Forgot to test, so here is updated version of recipe after fixes.
jevery23 Nov 2, 2017
2160e80
Remove .vs folder again.
jevery23 Nov 2, 2017
1de5d22
Ignore changes to .vs folder.
jevery23 Nov 2, 2017
65381ff
adding a fiddler debugging script
Nov 9, 2017
22d8fff
adding Praab's test script
Dec 8, 2017
17d7db1
Renaming file
Dec 8, 2017
5931c02
adding SAB script.
Dec 18, 2017
a12c222
Fixing a typo.
Dec 18, 2017
557b571
adding another SAB
Dec 18, 2017
9083634
Merge in fiddler collection stuff that Mustapha wrote.
jevery23 Jan 8, 2018
edc7f0c
Initial changes to recipe.
jevery23 Jan 8, 2018
447ac53
Merge in master.
jevery23 Jan 8, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions Recipe.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,64 @@ void function() { try {

} catch (ex) { /* do something maybe */ throw ex; } }();

/*
RECIPE: Pointer events and touch events
-------------------------------------------------------------
Author: joevery
Description: Find instances of listening for pointer and touch events.
*/

void function() {
window.CSSUsage.StyleWalker.recipesToRun.push(
function pointer_events_touch_events(/*HTML DOM Element*/ element, results) {
var nodeName = element.nodeName;
// We want to catch all instances of listening for these events.

var eventsToCheckFor = ["pointerup", "pointerdown", "pointermove", "pointercancel", "pointerout", "pointerleave", "pointerenter", "pointerover",
"touchstart", "touchend", "touchmove", "touchcancel"];

var isExternalJSAndNotRecipeJS = (element.src !== undefined && element.src !== "" && !element.src.includes("Recipe.min.js"));
var xhr;
if (isExternalJSAndNotRecipeJS)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this making XHRs for every single element with a src? (An image from an img tag, for example, would be pulled down as part of this). I think you'll want to do a check for nodeName == "SCRIPT" here as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or move this into the block of code where we know for sure we have an external script

Copy link
Owner Author

@jevery23 jevery23 Nov 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that's a good spot, I did not think of that case at all.

{
xhr = new XMLHttpRequest();
xhr.open("GET", element.src, false);
xhr.send();
}

for (const event of eventsToCheckFor) {

// Attribute specified on element, although this does not work at present.
if (element.getAttribute(".on" + event)) {
results[event] = results[event] || { count: 0, };
results[event].count++;
}

if (nodeName === "SCRIPT") {
// if inline script. ensure that it's not our recipe script and look for string of interest
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update comment here since we know that it's not our recipe script at this point (iirc, the recipe script is injected as a script tag, right?)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah so I was finding that the recipe would check the recipe.min.js script before this check was put in. Will update the comments as a result of the changes. :)

if ((element.text !== undefined) && (element.text.indexOf(event) !== -1)) {
var regex = new RegExp(event, 'g');
var instances = element.text.match(regex);

results[event] = results[event] || { count: 0, };
results[event].count += instances.length;
}
// if external script, then we have to go and get it and ensure it is not our recipe script.
else if (isExternalJSAndNotRecipeJS)
{
if (xhr.status === 200 && xhr.responseText.indexOf(event) !== -1) {
var regex = new RegExp(event, 'g');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Redundant code to the above. Could be pulled into a function.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah so I have packed all this stuff into the external script check if statement.

var instances = xhr.responseText.match(regex);

results[event] = results[event] || { count: 0, };
results[event].count += instances.length;
}
}
}
}
return results;
});
}();
//
// This file is only here to create the TSV
// necessary to collect the data from the crawler
Expand Down
58 changes: 58 additions & 0 deletions cssUsage.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,64 @@ void function() { try {

} catch (ex) { /* do something maybe */ throw ex; } }();

/*
RECIPE: Pointer events and touch events
-------------------------------------------------------------
Author: joevery
Description: Find instances of listening for pointer and touch events.
*/

void function() {
window.CSSUsage.StyleWalker.recipesToRun.push(
function pointer_events_touch_events(/*HTML DOM Element*/ element, results) {
var nodeName = element.nodeName;
// We want to catch all instances of listening for these events.

var eventsToCheckFor = ["pointerup", "pointerdown", "pointermove", "pointercancel", "pointerout", "pointerleave", "pointerenter", "pointerover",
"touchstart", "touchend", "touchmove", "touchcancel"];

var isExternalJSAndNotRecipeJS = (element.src !== undefined && element.src !== "" && !element.src.includes("Recipe.min.js"));
var xhr;
if (isExternalJSAndNotRecipeJS)
{
xhr = new XMLHttpRequest();
xhr.open("GET", element.src, false);
xhr.send();
}

for (const event of eventsToCheckFor) {

// Attribute specified on element, although this does not work at present.
if (element.getAttribute(".on" + event)) {
results[event] = results[event] || { count: 0, };
results[event].count++;
}

if (nodeName === "SCRIPT") {
// if inline script. ensure that it's not our recipe script and look for string of interest
if ((element.text !== undefined) && (element.text.indexOf(event) !== -1)) {
var regex = new RegExp(event, 'g');
var instances = element.text.match(regex);

results[event] = results[event] || { count: 0, };
results[event].count += instances.length;
}
// if external script, then we have to go and get it and ensure it is not our recipe script.
else if (isExternalJSAndNotRecipeJS)
{
if (xhr.status === 200 && xhr.responseText.indexOf(event) !== -1) {
var regex = new RegExp(event, 'g');
var instances = xhr.responseText.match(regex);

results[event] = results[event] || { count: 0, };
results[event].count += instances.length;
}
}
}
}
return results;
});
}();
//
// This file is only here to create the TSV
// necessary to collect the data from the crawler
Expand Down
58 changes: 58 additions & 0 deletions src/recipes/pointer-events_touch-events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
RECIPE: Pointer events and touch events
-------------------------------------------------------------
Author: joevery
Description: Find instances of listening for pointer and touch events.
*/

void function() {
window.CSSUsage.StyleWalker.recipesToRun.push(
function pointer_events_touch_events(/*HTML DOM Element*/ element, results) {
var nodeName = element.nodeName;
// We want to catch all instances of listening for these events.

var eventsToCheckFor = ["pointerup", "pointerdown", "pointermove", "pointercancel", "pointerout", "pointerleave", "pointerenter", "pointerover",
"touchstart", "touchend", "touchmove", "touchcancel"];

var isExternalJSAndNotRecipeJS = (element.src !== undefined && element.src !== "" && !element.src.includes("Recipe.min.js"));
var xhr;
if (isExternalJSAndNotRecipeJS)
{
xhr = new XMLHttpRequest();
xhr.open("GET", element.src, false);
xhr.send();
}

for (const event of eventsToCheckFor) {

// Attribute specified on element, although this does not work at present.
if (element.getAttribute(".on" + event)) {
results[event] = results[event] || { count: 0, };
results[event].count++;
}

if (nodeName === "SCRIPT") {
// if inline script. ensure that it's not our recipe script and look for string of interest
if ((element.text !== undefined) && (element.text.indexOf(event) !== -1)) {
var regex = new RegExp(event, 'g');
var instances = element.text.match(regex);

results[event] = results[event] || { count: 0, };
results[event].count += instances.length;
}
// if external script, then we have to go and get it and ensure it is not our recipe script.
else if (isExternalJSAndNotRecipeJS)
{
if (xhr.status === 200 && xhr.responseText.indexOf(event) !== -1) {
var regex = new RegExp(event, 'g');
var instances = xhr.responseText.match(regex);

results[event] = results[event] || { count: 0, };
results[event].count += instances.length;
}
}
}
}
return results;
});
}();
43 changes: 43 additions & 0 deletions tests/recipes/pointer-events_touch-events.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Pointer and touch events listening test</title>
<link type="text/css" href="../test-page/style.css" media="all" rel="stylesheet" />
<script src="../../Recipe.min.js"></script>
<style>
.square {
position: absolute;
left: 20px;
top: 10px;
bottom: 0px;
height: 200px;
width: 200px;
border: 5px blue solid;
-webkit-filter: blur(10px);
filter: blur(10px);
}
#square1 {
background-color: yellow;
left: 500px;
}
#square2 {
background-color: blue;
}
</style>
</head>
<body>
<!--Cannot test onpointerup on tag, but can test everything else.-->
<div class="wrapper">
<h1>Pointer and touch events listening test</h1>
<div id="shapes">
<div class="square" id="square1"></div>
<div class="square" id="square2" onload="func"></div>
</div>
</div>
<script src="../test-page/pointerevents.js"></script>
<script>
var square1 = document.getElementById("square1");
square1.ontouchstart = func2;
</script>
</body>
</html>
11 changes: 11 additions & 0 deletions tests/test-page/pointerevents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function func()
{
var square2 = document.getElementById("square2");

square2.addEventListener("pointerup", func2);
}

function func2()
{
alert("Point!!")
}