Discussion:
[chromium-discuss] Catch and handle a page's HTTP(S) requests
J Decker
2018-10-26 17:36:35 UTC
Permalink
I was working on downloading a service's UI from the service itself. The
service only allows one connection (websocket), and unless going through
the proper connection sequence, the service is not available. So once I
connect a websocket to the service, I can request "getClientInterface' at
which point the server can send HTML data which I set into an IFrame. The
Next issue, though, is that all the requests for external resources on that
page (Images/Style Sheets/More Scripts) are then requested from where the
top-level page is (and again, the service cannot be contacted again, even
if I used full resource paths including host).

I found that as an Extension there is an API for catching and modifying
requests, But isn't there some local handler I can setup just for this one
page?
--
--
Chromium Discussion mailing list: chromium-***@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-discuss

---
You received this message because you are subscribed to the Google Groups "Chromium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discuss+***@chromium.org.
PhistucK
2018-10-26 17:49:55 UTC
Permalink
Actually, there is - service worker. It is basically a worker (some sort of
a thread) that can listen to fetch requests (resources as well as AJAX and
similar) and respond/intercept.

☆*PhistucK*
Post by J Decker
I was working on downloading a service's UI from the service itself. The
service only allows one connection (websocket), and unless going through
the proper connection sequence, the service is not available. So once I
connect a websocket to the service, I can request "getClientInterface' at
which point the server can send HTML data which I set into an IFrame. The
Next issue, though, is that all the requests for external resources on that
page (Images/Style Sheets/More Scripts) are then requested from where the
top-level page is (and again, the service cannot be contacted again, even
if I used full resource paths including host).
I found that as an Extension there is an API for catching and modifying
requests, But isn't there some local handler I can setup just for this one
page?
--
--
http://groups.google.com/a/chromium.org/group/chromium-discuss
---
You received this message because you are subscribed to the Google Groups
"Chromium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
--
Chromium Discussion mailing list: chromium-***@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-discuss

---
You received this message because you are subscribed to the Google Groups "Chromium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discuss+***@chromium.org.
J Decker
2018-11-06 04:41:38 UTC
Permalink
I have this gist of what I'm trying to do...
https://gist.github.com/d3x0r/8e09d2c94472986d57f2941cf5079d66


---
Service loader ran once?
(index):34 GET https://localhost:8085/styles.css net::ERR_ABORTED 404 (OK)
redirectHandler.addEventListener @ (index):34
load (async)
(anonymous) @ (index):33
Logo.png:1 GET Loading Image... 404 (OK)
Image (async)
redirectHandler.addEventListener @ (index):34
load (async)
(anonymous) @ (index):33
redirectLoader.js:17 (rloader)ServiceWorker registration failed:
DOMException: Failed to register a ServiceWorker: No URL is associated with
the caller's document.
An SSL certificate error occurred when fetching the script.
Failed to load resource: net::ERR_CERT_AUTHORITY_INVALID
(index):49 ServiceWorker registration failed: DOMException: Failed to
register a ServiceWorker: An SSL certificate error occurred when fetching
the script.
---

In the first case, I have this service that serves its content over a
websocket; it is a https server, and the root certificate is installed in
the system.
I am having problems with this second page triggering fetch events in the
service worker...

So I started to make a simpler example, using an HTTP server but was having
problems getting the service worker to work (did some searching, found it
has to be https)
so, started a simple https server, with a root cert/ca/cert chain, but the
root certicate is not installed....

"An SSL certificate error occurred when fetching the script."

Other than I had already accepted the cert for the page itself, which is
all one service point....

----------
So as I was writing this, copied to another server that is a letsEncrypt
certificate

Service loader ran once?
(index):34 GET https://d3x0r.org:444/javascript/minTest/styles.css
net::ERR_ABORTED 404 (Not Found)
redirectHandler.addEventListener @ (index):34
load (async)
(anonymous) @ (index):33
Logo.png:1 GET Loading Image... 404
(Not Found)
Image (async)
redirectHandler.addEventListener @ (index):34
load (async)
(anonymous) @ (index):33
redirectLoader.js:17 (rloader)ServiceWorker registration failed:
DOMException: Failed to register a ServiceWorker: No URL is associated with
the caller's document.
redirectWorker.js:47 Service ran once?
(index):46 ServiceWorker registration successful with scope:
https://d3x0r.org:444/javascript/minTest/
redirectWorker.js:4 Installation event

-----------
But still, the fetch event for the loaded page is not loaded. There are no
external links on the index.html, just on the 'newPage' that is loaded....

----------------
But; to get this to work, say the websocket connection in in 'login.js' ,
and I can't just give that connection to the worker to use... so I have to
have the worker post (to some client) when it gets a fetch request so the
client can use the appropriate socket and get additional contents; which
then has to post back to the service worker the data for it.

Since the service worker can be shared between multiple clients, how do I
know which client to ask for the additional content?
Post by PhistucK
Actually, there is - service worker. It is basically a worker (some sort
of a thread) that can listen to fetch requests (resources as well as AJAX
and similar) and respond/intercept.
☆*PhistucK*
Post by J Decker
I was working on downloading a service's UI from the service itself. The
service only allows one connection (websocket), and unless going through
the proper connection sequence, the service is not available. So once I
connect a websocket to the service, I can request "getClientInterface' at
which point the server can send HTML data which I set into an IFrame. The
Next issue, though, is that all the requests for external resources on that
page (Images/Style Sheets/More Scripts) are then requested from where the
top-level page is (and again, the service cannot be contacted again, even
if I used full resource paths including host).
I found that as an Extension there is an API for catching and modifying
requests, But isn't there some local handler I can setup just for this one
page?
--
--
http://groups.google.com/a/chromium.org/group/chromium-discuss
---
You received this message because you are subscribed to the Google Groups
"Chromium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
--
Chromium Discussion mailing list: chromium-***@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-discuss

---
You received this message because you are subscribed to the Google Groups "Chromium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discuss+***@chromium.org.
Loading...