{"action":"created","comment":{"url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/pulls/comments/154127910","pull_request_review_id":80229405,"id":154127910,"diff_hunk":"@@ -0,0 +1,178 @@\n+import { PNG } from \"pngjs\";\n+import {\n+    ILocation,\n+    ISize,\n+    WebDriver,\n+    WebElement,\n+} from \"selenium-webdriver\";\n+\n+const SVR_ID = \"added-by-snappit-visual-regression\";\n+const DROP_SCROLLBARS = `\n+var head = document.querySelector(\"head\");\n+var style = document.createElement(\"style\");\n+style.id = \"${SVR_ID}\";\n+style.type = \"text/css\";\n+style.innerText = \"::-webkit-scrollbar { display: none; }\"\n+head.appendChild(style);\n+`;\n+\n+const REMOVE_DROP_SCROLLBARS = `\n+document.querySelector('#${SVR_ID}').remove();\n+`;\n+\n+class ElementScreenshot {\n+    private devicePixelRatio: number;\n+    private driver: WebDriver;\n+    private element: WebElement;\n+    private elementScreenshot: PNG; // final result\n+    private loc: ILocation; // element location\n+    private screenshotsHeightwise: number;\n+    private screenshotsLengthwise: number;\n+    private size: ISize; // element size\n+    private viewport: ISize;\n+    private x: number; // browser window's current X position\n+    private y: number; // browser window's current Y position\n+\n+    constructor(\n+        driver: WebDriver,\n+        element: WebElement,\n+    ) {\n+        this.driver = driver;\n+        this.element = element;\n+    }\n+    /**\n+     * Constructor functions cannot be async. This will bootstrap some shared values used between\n+     * the logic that takes *all* screenshots and the one that takes *the majority* of the screenshots.\n+     */\n+    public async prepare() {\n+        this.devicePixelRatio = (await this.driver.executeScript(\"return window.devicePixelRatio\")) as number;\n+\n+        if (process.env.CI) {\n+            const measurementScreenshot = await this.ss();\n+            this.viewport = {\n+                height: measurementScreenshot.height,\n+                width: measurementScreenshot.width,\n+            };\n+\n+        } else {\n+            this.viewport = {\n+                height: (await this.driver.executeScript(\"return window.innerHeight\")) as number,\n+                width: (await this.driver.executeScript(\"return window.innerWidth\")) as number,\n+            };\n+\n+            const firefoxHeadless = (await this.driver.getCapabilities()).get(\"moz:headless\");\n+            if (firefoxHeadless) {\n+                // I think this is used because FF headless doesn't consider scrollbars as part of the viewport...?\n+                const OFFSET = 15; // pixels\n+                this.viewport.height = this.viewport.height -= OFFSET;\n+                this.viewport.width = this.viewport.width -= OFFSET;\n+            }\n+        }\n+\n+        this.size = await this.element.getSize();\n+        this.loc = await this.element.getLocation();\n+\n+        this.screenshotsLengthwise = Math.floor(this.size.width / this.viewport.width);\n+        this.screenshotsHeightwise = Math.floor(this.size.height / this.viewport.height);\n+\n+        // these get mutated quite frequently...\n+        this.x = this.loc.x;\n+        this.y = this.loc.y;\n+        this.elementScreenshot = new PNG({\n+            height: this.size.height * this.devicePixelRatio,\n+            width: this.size.width * this.devicePixelRatio,\n+        });\n+\n+        return this;\n+    }\n+\n+    public async take() {\n+        const singleScreenshotOnly = this.screenshotsLengthwise === 0 && this.screenshotsHeightwise === 0;\n+        if (singleScreenshotOnly) {\n+            await this.scroll();\n+            const scrollPositionX = await this.driver.executeScript(\"return window.pageXOffset;\") as number;\n+            const scrollPositionY = await this.driver.executeScript(\"return window.pageYOffset;\") as number;\n+            const rootX = this.loc.x - scrollPositionX;\n+            const rootY = this.loc.y - scrollPositionY;","path":"src/elementScreenshot.ts","position":96,"original_position":96,"commit_id":"00a62b3fdb85da82dee67c924e8e2d421345c718","original_commit_id":"00a62b3fdb85da82dee67c924e8e2d421345c718","user":{"login":"rbcasperson","id":15185836,"avatar_url":"https://avatars2.githubusercontent.com/u/15185836?v=4","gravatar_id":"","url":"https://api.github.com/users/rbcasperson","html_url":"https://github.com/rbcasperson","followers_url":"https://api.github.com/users/rbcasperson/followers","following_url":"https://api.github.com/users/rbcasperson/following{/other_user}","gists_url":"https://api.github.com/users/rbcasperson/gists{/gist_id}","starred_url":"https://api.github.com/users/rbcasperson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rbcasperson/subscriptions","organizations_url":"https://api.github.com/users/rbcasperson/orgs","repos_url":"https://api.github.com/users/rbcasperson/repos","events_url":"https://api.github.com/users/rbcasperson/events{/privacy}","received_events_url":"https://api.github.com/users/rbcasperson/received_events","type":"User","site_admin":false},"body":"How about moving this into `this.findElementCoordinatesInViewport` (or whatever you like)?","created_at":"2017-11-30T16:28:01Z","updated_at":"2017-11-30T17:01:21Z","html_url":"https://github.com/rackerlabs/snappit-visual-regression/pull/25#discussion_r154127910","pull_request_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/pulls/25","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/pulls/comments/154127910"},"html":{"href":"https://github.com/rackerlabs/snappit-visual-regression/pull/25#discussion_r154127910"},"pull_request":{"href":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/pulls/25"}}},"pull_request":{"url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/pulls/25","id":154602806,"html_url":"https://github.com/rackerlabs/snappit-visual-regression/pull/25","diff_url":"https://github.com/rackerlabs/snappit-visual-regression/pull/25.diff","patch_url":"https://github.com/rackerlabs/snappit-visual-regression/pull/25.patch","issue_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/issues/25","number":25,"state":"open","locked":false,"title":"Crop and stitch","user":{"login":"Droogans","id":1214609,"avatar_url":"https://avatars0.githubusercontent.com/u/1214609?v=4","gravatar_id":"","url":"https://api.github.com/users/Droogans","html_url":"https://github.com/Droogans","followers_url":"https://api.github.com/users/Droogans/followers","following_url":"https://api.github.com/users/Droogans/following{/other_user}","gists_url":"https://api.github.com/users/Droogans/gists{/gist_id}","starred_url":"https://api.github.com/users/Droogans/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Droogans/subscriptions","organizations_url":"https://api.github.com/users/Droogans/orgs","repos_url":"https://api.github.com/users/Droogans/repos","events_url":"https://api.github.com/users/Droogans/events{/privacy}","received_events_url":"https://api.github.com/users/Droogans/received_events","type":"User","site_admin":false},"body":"Closes #21","created_at":"2017-11-24T19:59:57Z","updated_at":"2017-11-30T17:01:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"16f738fc11e8809a3c1ce05751a04b5653b0886e","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/pulls/25/commits","review_comments_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/pulls/25/comments","review_comment_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/issues/25/comments","statuses_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/statuses/00a62b3fdb85da82dee67c924e8e2d421345c718","head":{"label":"rackerlabs:crop-and-stitch","ref":"crop-and-stitch","sha":"00a62b3fdb85da82dee67c924e8e2d421345c718","user":{"login":"rackerlabs","id":84293,"avatar_url":"https://avatars1.githubusercontent.com/u/84293?v=4","gravatar_id":"","url":"https://api.github.com/users/rackerlabs","html_url":"https://github.com/rackerlabs","followers_url":"https://api.github.com/users/rackerlabs/followers","following_url":"https://api.github.com/users/rackerlabs/following{/other_user}","gists_url":"https://api.github.com/users/rackerlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/rackerlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rackerlabs/subscriptions","organizations_url":"https://api.github.com/users/rackerlabs/orgs","repos_url":"https://api.github.com/users/rackerlabs/repos","events_url":"https://api.github.com/users/rackerlabs/events{/privacy}","received_events_url":"https://api.github.com/users/rackerlabs/received_events","type":"Organization","site_admin":false},"repo":{"id":90758377,"name":"snappit-visual-regression","full_name":"rackerlabs/snappit-visual-regression","owner":{"login":"rackerlabs","id":84293,"avatar_url":"https://avatars1.githubusercontent.com/u/84293?v=4","gravatar_id":"","url":"https://api.github.com/users/rackerlabs","html_url":"https://github.com/rackerlabs","followers_url":"https://api.github.com/users/rackerlabs/followers","following_url":"https://api.github.com/users/rackerlabs/following{/other_user}","gists_url":"https://api.github.com/users/rackerlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/rackerlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rackerlabs/subscriptions","organizations_url":"https://api.github.com/users/rackerlabs/orgs","repos_url":"https://api.github.com/users/rackerlabs/repos","events_url":"https://api.github.com/users/rackerlabs/events{/privacy}","received_events_url":"https://api.github.com/users/rackerlabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rackerlabs/snappit-visual-regression","description":"An NPM module for visual regression testing","fork":false,"url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression","forks_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/forks","keys_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/teams","hooks_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/hooks","issue_events_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/issues/events{/number}","events_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/events","assignees_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/assignees{/user}","branches_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/branches{/branch}","tags_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/tags","blobs_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/git/refs{/sha}","trees_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/statuses/{sha}","languages_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/languages","stargazers_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/stargazers","contributors_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/contributors","subscribers_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/subscribers","subscription_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/subscription","commits_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/commits{/sha}","git_commits_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/git/commits{/sha}","comments_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/comments{/number}","issue_comment_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/issues/comments{/number}","contents_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/contents/{+path}","compare_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/merges","archive_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/downloads","issues_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/issues{/number}","pulls_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/pulls{/number}","milestones_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/milestones{/number}","notifications_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/labels{/name}","releases_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/releases{/id}","deployments_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/deployments","created_at":"2017-05-09T14:55:18Z","updated_at":"2017-11-30T16:25:47Z","pushed_at":"2017-11-28T22:51:13Z","git_url":"git://github.com/rackerlabs/snappit-visual-regression.git","ssh_url":"git@github.com:rackerlabs/snappit-visual-regression.git","clone_url":"https://github.com/rackerlabs/snappit-visual-regression.git","svn_url":"https://github.com/rackerlabs/snappit-visual-regression","homepage":null,"size":219,"stargazers_count":2,"watchers_count":2,"language":"TypeScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":4,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":1,"open_issues":4,"watchers":2,"default_branch":"master"}},"base":{"label":"rackerlabs:master","ref":"master","sha":"aa4a2302cfde436a0b47136c2353de49eaafb7e5","user":{"login":"rackerlabs","id":84293,"avatar_url":"https://avatars1.githubusercontent.com/u/84293?v=4","gravatar_id":"","url":"https://api.github.com/users/rackerlabs","html_url":"https://github.com/rackerlabs","followers_url":"https://api.github.com/users/rackerlabs/followers","following_url":"https://api.github.com/users/rackerlabs/following{/other_user}","gists_url":"https://api.github.com/users/rackerlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/rackerlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rackerlabs/subscriptions","organizations_url":"https://api.github.com/users/rackerlabs/orgs","repos_url":"https://api.github.com/users/rackerlabs/repos","events_url":"https://api.github.com/users/rackerlabs/events{/privacy}","received_events_url":"https://api.github.com/users/rackerlabs/received_events","type":"Organization","site_admin":false},"repo":{"id":90758377,"name":"snappit-visual-regression","full_name":"rackerlabs/snappit-visual-regression","owner":{"login":"rackerlabs","id":84293,"avatar_url":"https://avatars1.githubusercontent.com/u/84293?v=4","gravatar_id":"","url":"https://api.github.com/users/rackerlabs","html_url":"https://github.com/rackerlabs","followers_url":"https://api.github.com/users/rackerlabs/followers","following_url":"https://api.github.com/users/rackerlabs/following{/other_user}","gists_url":"https://api.github.com/users/rackerlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/rackerlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rackerlabs/subscriptions","organizations_url":"https://api.github.com/users/rackerlabs/orgs","repos_url":"https://api.github.com/users/rackerlabs/repos","events_url":"https://api.github.com/users/rackerlabs/events{/privacy}","received_events_url":"https://api.github.com/users/rackerlabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rackerlabs/snappit-visual-regression","description":"An NPM module for visual regression testing","fork":false,"url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression","forks_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/forks","keys_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/teams","hooks_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/hooks","issue_events_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/issues/events{/number}","events_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/events","assignees_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/assignees{/user}","branches_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/branches{/branch}","tags_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/tags","blobs_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/git/refs{/sha}","trees_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/statuses/{sha}","languages_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/languages","stargazers_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/stargazers","contributors_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/contributors","subscribers_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/subscribers","subscription_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/subscription","commits_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/commits{/sha}","git_commits_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/git/commits{/sha}","comments_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/comments{/number}","issue_comment_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/issues/comments{/number}","contents_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/contents/{+path}","compare_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/merges","archive_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/downloads","issues_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/issues{/number}","pulls_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/pulls{/number}","milestones_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/milestones{/number}","notifications_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/labels{/name}","releases_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/releases{/id}","deployments_url":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/deployments","created_at":"2017-05-09T14:55:18Z","updated_at":"2017-11-30T16:25:47Z","pushed_at":"2017-11-28T22:51:13Z","git_url":"git://github.com/rackerlabs/snappit-visual-regression.git","ssh_url":"git@github.com:rackerlabs/snappit-visual-regression.git","clone_url":"https://github.com/rackerlabs/snappit-visual-regression.git","svn_url":"https://github.com/rackerlabs/snappit-visual-regression","homepage":null,"size":219,"stargazers_count":2,"watchers_count":2,"language":"TypeScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":4,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":1,"open_issues":4,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/pulls/25"},"html":{"href":"https://github.com/rackerlabs/snappit-visual-regression/pull/25"},"issue":{"href":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/issues/25"},"comments":{"href":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/issues/25/comments"},"review_comments":{"href":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/pulls/25/comments"},"review_comment":{"href":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/pulls/25/commits"},"statuses":{"href":"https://api.github.com/repos/rackerlabs/snappit-visual-regression/statuses/00a62b3fdb85da82dee67c924e8e2d421345c718"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"rbcasperson"}}