Skip to content

Commit

Permalink
Add dismissModal functionality.
Browse files Browse the repository at this point in the history
Does a tab and escape keypress to try to dismiss any modals.
  • Loading branch information
James Jacobs committed Dec 15, 2023
1 parent 488d39d commit 12ef248
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
7 changes: 6 additions & 1 deletion API/REST/Screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ exports.handler = async (event, context, callback) => {
console.error("can't parse headers");
}
}
var dismissModals = false;
if (event.queryStringParameters.dismissModals == "true") {
dismissModals = true;
}

//var screenshotResult = await tools.screnshotForUrl(url, isFullPage, resX, resY, outFormat);
var screenshotResult = null;
Expand All @@ -92,7 +96,8 @@ exports.handler = async (event, context, callback) => {
outFormat,
orientation,
waitTime,
proxy_server
proxy_server,
dismissModals,
);
} catch (ex) {
//do nothing
Expand Down
5 changes: 3 additions & 2 deletions API/WS/Screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ exports.message = async (event, context, callback) => {
screenshotResult = await tools.screnshotForUrlTab(
url,
obj.headers,
obj.isFullPage,
(/true/).test(obj.isFullPage),
obj.resX,
obj.resY,
obj.outFormat,
obj.orientation,
obj.waitTime,
proxy_server
proxy_server,
(/true/).test(obj.dismissModals),
);
} catch (ex) {
//do nothing
Expand Down
11 changes: 10 additions & 1 deletion API/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ module.exports.screnshotForUrlTab = async function (
outFormat,
orientation,
waitTime,
proxy_server
proxy_server,
dismissModals,
) {
return new Promise(async function (resolve, reject) {
try {
Expand Down Expand Up @@ -82,6 +83,14 @@ module.exports.screnshotForUrlTab = async function (
});
} catch (ex) {}

//Try to dismiss modals by sending Tab and Esc
if (dismissModals) {
try {
await page.keyboard.press('Tab');
await page.keyboard.press('Escape');
} catch (ex) {}
}

var finalType = "jpg";
var finalMime = "image/jpeg";

Expand Down
15 changes: 13 additions & 2 deletions public/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,20 @@ function connect() {
}

var sendQueue = [];
function AskForScreenshot(url, resX, resY, outFormat, isFullPage, waitTime){
function AskForScreenshot(url, resX, resY, outFormat, isFullPage, waitTime, dismissModals){
$("#resultImg").hide();
$("#stats").html("Please wait ...");
var event = { cmd: "screenshot", url: url, originalTS: (+new Date()), resX: resX, resY: resY, outFormat: outFormat, isFullPage: isFullPage, waitTime: waitTime };
var event = {
cmd: "screenshot",
url: url,
originalTS: (+new Date()),
resX: resX,
resY: resY,
outFormat: outFormat,
isFullPage: isFullPage,
waitTime: waitTime,
dismissModals: dismissModals,
};
Send(event);
}

Expand Down Expand Up @@ -128,6 +138,7 @@ function UpdateRESTUrl(){
baseUrl += "&outFormat=" + $("#outFormat").val();
baseUrl += "&waitTime=" + $("#waitTime").val();
baseUrl += "&isFullPage=" + document.getElementById("isFullPage").checked;
baseUrl += "&dismissModals=" + document.getElementById("dismissModals").checked;

if ( $("#fieldUrl").val().indexOf("&") > -1 ){
baseUrl += "&url=" + encodeURIComponent( $("#fieldUrl").val() )
Expand Down
2 changes: 1 addition & 1 deletion public/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ h1 {
margin-right: 5px;
}

.screenshot__wait-time, .screenshot__full-page {
.screenshot__wait-time, .screenshot__full-page, .screenshot__dismiss-modals {
margin-left: 25px;
margin-right: 5px;
}
Expand Down
5 changes: 3 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ <h1>A simple way to take a screenshot of a website by providing its URL</h1>
</select>
</div>
<input class="screenshot__full-page" id="isFullPage" type="checkbox" onchange="UpdateRESTUrl()"> Full page screenshot
<input class="screenshot__dismiss-modals" id="dismissModals" type="checkbox" onchange="UpdateRESTUrl()"> Dismiss modals
<div class="left screenshot__wait-time">
<span>Wait time before screenshot </span> <input class="screenshot__input-options mleft-5" id="waitTime" type="number" min="0" max="30000" value="100" onchange="UpdateRESTUrl()"> ms
</div>
Expand Down Expand Up @@ -93,8 +94,8 @@ <h1>A simple way to take a screenshot of a website by providing its URL</h1>
var outFormat = document.getElementById("outFormat").value;
var isFullPage = document.getElementById("isFullPage").checked;
var waitTime = document.getElementById("waitTime").value;

AskForScreenshot(url, resX, resY, outFormat, isFullPage, waitTime);
var dismissModals = document.getElementById("dismissModals").checked;
AskForScreenshot(url, resX, resY, outFormat, isFullPage, waitTime, dismissModals);
}

</script>
Expand Down

0 comments on commit 12ef248

Please sign in to comment.