-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parameterize the cors and proxy options #5
Open
saikris12
wants to merge
6
commits into
sudharsan-selvaraj:master
Choose a base branch
from
saikris12:feature/proxy-cors-options
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+85
−6
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
882e4d5
Added proxy config to overcome cors issue for images
21b42ba
Merge pull request #1 from saikris12/feature/accept-proxy-url
saikris12 9affe66
Merge branch 'master' of https://github.com/saikris12/protractor-scre…
5dedc62
Parameterize the proxy and cors options
cf3fd72
Remove duplicate entry in README
1f5a50e
Expose all available html2canvas options
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ interface configOptions { | |
* 1. element(OPTIONAL) - to take screenshot of any particular element. | ||
* 2. dimensions(OPTIONAL) - to crop the screen shot based on x,y,width and height of the screnshot. | ||
* 3. saveTo(OPTIONAL) - file path to automatically save the processed screenshot. | ||
* 4. canvasOptions(OPTIONAL) - options to pass to html2canvas | ||
*/ | ||
interface screenShotOptions { | ||
element?:ElementFinder; | ||
|
@@ -20,7 +21,36 @@ interface screenShotOptions { | |
width:number, | ||
height:number | ||
}, | ||
saveTo?:string | ||
saveTo?:string, | ||
canvasOptions?:canvasOptions | ||
} | ||
|
||
/** | ||
* Options that can to be passed as parameter to `html2canvas` method. | ||
* Refer to https://html2canvas.hertzen.com/configuration for usage | ||
*/ | ||
|
||
interface canvasOptions { | ||
allowTaint?: boolean, | ||
backgroundColor?: string, | ||
canvas?: HTMLCanvasElement, | ||
foreignObjectRendering?: boolean, | ||
imageTimeout?: number, | ||
ignoreElements?: (element: Element) => boolean; | ||
logging?: boolean, | ||
onclone?: (document: Document) => void, | ||
proxy?: string, | ||
removeContainer?: boolean, | ||
scale?: number, | ||
useCORS?: boolean, | ||
width?: number, | ||
height?: number, | ||
x?: number, | ||
y?: number, | ||
scrollX?: number, | ||
scrollY?: number, | ||
windowWidth?: number, | ||
windowHeight?: number | ||
} | ||
|
||
let html2canvasPath = require.resolve("html2canvas").replace("/npm/index.js", "/html2canvas.min.js"); | ||
|
@@ -68,11 +98,13 @@ class ProtractorScreenShotUtils { | |
element:ElementFinder = options.element ? options.element : currentContext.$("body"), | ||
dimensions = options.dimensions || {}, | ||
outputPath = options.saveTo || null, | ||
canvasOptions = options.canvasOptions || {}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about we include the canvasOptions in the constructor and use it as a default option. we can also override the default options when calling the takeScreenshot method? |
||
html2canvasScript = fs.readFileSync(html2canvasPath, 'utf8'), | ||
injectionScript = | ||
`var callBack = arguments[arguments.length -1]; | ||
var dimensions = arguments[1]; | ||
html2canvas(arguments[0], {allowTaint : true, useCORS: true}).then(function(canvas){ | ||
var canvasOptions = arguments[2]; | ||
html2canvas(arguments[0],canvasOptions).then(function(canvas){ | ||
|
||
if(Object.keys(dimensions).length == 4) { | ||
console.log("Success"); | ||
|
@@ -92,7 +124,7 @@ class ProtractorScreenShotUtils { | |
})`; | ||
|
||
return currentContext.executeScript(`${html2canvasScript}`).then(function () { | ||
return currentContext.executeAsyncScript(injectionScript, element.getWebElement(), dimensions).then(function (base64String:string) { | ||
return currentContext.executeAsyncScript(injectionScript, element.getWebElement(), dimensions, canvasOptions).then(function (base64String:string) { | ||
base64String = base64String.replace(/^data:image\/png;base64,/, ""); | ||
|
||
/*if output path is given, then save the screenshot as file*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻