@@ -21,7 +21,8 @@ import (
2121)
2222
2323// listenForEventRequestPaused listens for requests to check if they are
24- // allowed or not.
24+ // allowed or not.network.SetBlockedURLS()
25+ // TODO: https://chromedevtools.github.io/devtools-protocol/tot/Network/#method-setBlockedURLs (experimental for now).
2526func listenForEventRequestPaused (ctx context.Context , logger * zap.Logger , allowList * regexp2.Regexp , denyList * regexp2.Regexp ) {
2627 chromedp .ListenTarget (ctx , func (ev interface {}) {
2728 switch e := ev .(type ) {
@@ -95,24 +96,48 @@ func listenForEventResponseReceived(ctx context.Context, logger *zap.Logger, url
9596 })
9697}
9798
98- // listenForEventLoadingFailedOnConnectionRefused listens for an event
99- // indicating that the main page failed to load.
100- // See https://github.com/gotenberg/gotenberg/issues/913.
101- func listenForEventLoadingFailedOnConnectionRefused (ctx context.Context , logger * zap.Logger , connectionRefused * error , connectionRefusedMu * sync.RWMutex ) {
99+ // listenForEventLoadingFailed listens for an event indicating that the main
100+ // page failed to load.
101+ // See:
102+ // https://github.com/gotenberg/gotenberg/issues/913.
103+ // https://github.com/gotenberg/gotenberg/issues/959.
104+ func listenForEventLoadingFailed (ctx context.Context , logger * zap.Logger , loadingFailed * error , loadingFailedMu * sync.RWMutex ) {
102105 chromedp .ListenTarget (ctx , func (ev interface {}) {
103106 switch ev := ev .(type ) {
104107 case * network.EventLoadingFailed :
105108 logger .Debug (fmt .Sprintf ("event EventLoadingFailed fired: %+v" , ev .ErrorText ))
106109
107- if ev .ErrorText != "net::ERR_CONNECTION_REFUSED" || ev . Type != network .ResourceTypeDocument {
108- logger .Debug ("skip EventLoadingFailed: is not net::ERR_CONNECTION_REFUSED and/or resource type Document" )
110+ if ev .Type != network .ResourceTypeDocument {
111+ logger .Debug ("skip EventLoadingFailed: is not resource type Document" )
109112 return
110113 }
111114
112- connectionRefusedMu . Lock ()
113- defer connectionRefusedMu . Unlock ()
115+ // Supposition: except iframe, an event loading failed with a
116+ // resource type Document is about the main page.
114117
115- * connectionRefused = fmt .Errorf ("%s" , ev .ErrorText )
118+ // We are looking for common errors.
119+ // TODO: sufficient?
120+ errors := []string {
121+ "net::ERR_CONNECTION_CLOSED" ,
122+ "net::ERR_CONNECTION_RESET" ,
123+ "net::ERR_CONNECTION_REFUSED" ,
124+ "net::ERR_CONNECTION_ABORTED" ,
125+ "net::ERR_CONNECTION_FAILED" ,
126+ "net::ERR_NAME_NOT_RESOLVED" ,
127+ "net::ERR_INTERNET_DISCONNECTED" ,
128+ "net::ERR_ADDRESS_UNREACHABLE" ,
129+ "net::ERR_BLOCKED_BY_CLIENT" ,
130+ "net::ERR_BLOCKED_BY_RESPONSE" ,
131+ }
132+ if ! slices .Contains (errors , ev .ErrorText ) {
133+ logger .Debug (fmt .Sprintf ("skip EventLoadingFailed: '%s' is not part of %+v" , ev .ErrorText , errors ))
134+ return
135+ }
136+
137+ loadingFailedMu .Lock ()
138+ defer loadingFailedMu .Unlock ()
139+
140+ * loadingFailed = fmt .Errorf ("%s" , ev .ErrorText )
116141 }
117142 })
118143}
0 commit comments