You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: screenshot.go
+75-57Lines changed: 75 additions & 57 deletions
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,6 @@ package urlbox
3
3
import (
4
4
"errors"
5
5
"fmt"
6
-
"io"
7
6
"net/http"
8
7
)
9
8
@@ -14,139 +13,158 @@ var (
14
13
15
14
type (
16
15
Requeststruct {
17
-
Urlstring// url of website to screenshot
18
-
Format*string// screenshot file format
16
+
Urlstring`json:"url"`// url of website to screenshot
17
+
Formatstring`json:"fornmat"`// screenshot file format
19
18
OptionsOptions// optional params for the request
20
19
}
21
20
Optionsstruct {
22
-
FullPage*bool// for full page screenshot
23
-
Width*string
21
+
FullPagebool// for full page screenshot
22
+
Widthint
24
23
BlockingOptionsBlocking// options for blocking or dismissing certain page elements, such as cookie banners
25
24
SelectorOptionSelector// selector parameter
26
25
ImageOptionImage// options relating to the outputted PNG, WebP or JPEG file
27
-
DownloadDownload// pass in a filename which sets the content-disposition header on the response. E.g. download=myfilename.png This will make the Urlbox link downloadable, and will prompt the user to save the file as myfilename.png
26
+
DownloadOptionDownload// pass in a filename which sets the content-disposition header on the response. E.g. download=myfilename.png This will make the Urlbox link downloadable, and will prompt the user to save the file as myfilename.png
28
27
WaitOptionWait
29
28
}
30
29
Blockingstruct {
31
-
BlockAds*bool// remove ads from page
32
-
HideCookieBanners*bool// remove cookie banners if any
33
-
ClickAccept*bool// click accept buttons to dismiss pop-upsSelector
30
+
BlockAdsbool`json:"block_ads"`// remove ads from page
31
+
HideCookieBannersbool`json:"hide_cookie_banners"`// remove cookie banners if any
32
+
ClickAcceptbool`json:"click_accept"`// click accept buttons to dismiss pop-upsSelector
34
33
}
35
34
Selectorstruct {
36
-
Selector*string// for css selectors e.g #playground for id of playground
37
-
FailIfSelectorMissing*bool// fail the request when the selector is not found
35
+
Selectorstring`json:"selector"`// for css selectors e.g #playground for id of playground
36
+
FailIfSelectorMissingbool`json:"fail_if_selector_missing"`// fail the request when the selector is not found
38
37
}
39
38
40
39
Imagestruct {
41
-
Retina*bool// take a 'retina' or high-definition screenshot, equivalent to setting a device pixel ratio of 2.0 or @2x. Please note that retina screenshots will be double the normal dimensions and will normally take slightly longer to process due to the much bigger image size.
42
-
Qualityint// the image quality of the resulting screenshot (JPEG/WebP only)
43
-
}
44
-
45
-
Waitstruct {
46
-
Delay*int// the amount of time to wait before Urlbox takes the screenshot or PDF, in milliseconds.
47
-
TimeOut*int// the amount of time to wait for the requested URL to respond, in milliseconds.
40
+
Retinabool`json:"retina"`// take a 'retina' or high-definition screenshot, equivalent to setting a device pixel ratio of 2.0 or @2x. Please note that retina screenshots will be double the normal dimensions and will normally take slightly longer to process due to the much bigger image size.
41
+
Qualityint`json:"quality"`// the image quality of the resulting screenshot (JPEG/WebP only)
48
42
}
49
43
50
44
Downloadstruct {
51
45
DownloadFilebool
52
-
FileName*string
46
+
FileNamestring`json:"download"`
53
47
}
54
48
55
-
Responsestruct {
56
-
File io.ReadCloser`json:"file"`
49
+
Waitstruct {
50
+
Delayint// the amount of time to wait before Urlbox takes the screenshot or PDF, in milliseconds.
51
+
TimeOutint// the amount of time to wait for the requested URL to respond, in milliseconds.
57
52
}
58
53
)
59
54
60
-
// parse() sets up default values if the user doesnt pass any params in
55
+
// parse() sets up default values if the user doesn't pass any params in
61
56
func (rRequest) parse() Request {
62
57
// if a file format is not provided, set file format as png
63
-
ifr.Format==nil {
58
+
ifr.Format=="" {
64
59
png:=FileFormatPng
65
-
r.Format=&png
60
+
r.Format=png
66
61
}
67
62
// if FullPage Options field is not passed set to false
68
-
ifr.Options.FullPage==nil {
63
+
if!r.Options.FullPage {
69
64
fullPage:=false
70
-
r.Options.FullPage=&fullPage
65
+
r.Options.FullPage=fullPage
71
66
}
72
67
// if Width Options field is not passed set to DefaultWidth
73
-
ifr.Options.Width==nil {
68
+
ifr.Options.Width==0 {
74
69
width:=DefaultWidth
75
-
r.Options.Width=&width
70
+
r.Options.Width=width
76
71
}
77
72
// if BlockAds Options field is not passed set to true
78
-
ifr.Options.BlockingOptions.BlockAds==nil {
73
+
if!r.Options.BlockingOptions.BlockAds {
79
74
blockAds:=true
80
-
r.Options.BlockingOptions.BlockAds=&blockAds
75
+
r.Options.BlockingOptions.BlockAds=blockAds
81
76
}
82
77
// if HideCookieBanners Options field is not passed set to true
0 commit comments