penge/block-site

Blocking home page only

Closed this issue · 5 comments

bard commented

Thanks for this extension!

This may be a feature request or a just a question, not sure.

I'd like to block a home page but allow everything else or, at least, specific paths. I tried the following but it didn't work:

youtube.com
!youtube.com/watch
!youtube.com/results

Is that currently possible?

EDIT: I was mistaken, it appears to work just fine. I think I assumed that rules are saved on textarea blur but they seem to be saved on window close. Either way, apologies for the noise and thanks again for sharing your work!

bard commented

So, it's a little more complex and the reason has nothing to do with my edit above:

  1. If you visit the home page from a video page by left-clicking on the top-left logo, the page is not blocked.
  2. If you visit the home page from a video page by middle-clicking on the top-left logo, the page is blocked.
  3. If you visit the home page from a new tab page by entering youtube.com in the address bar, the page is blocked.

Perhaps in case 1) the History API is used instead of a full page reload and that is not intercepted?

penge commented

Hi @bard!

EDIT: I was mistaken, it appears to work just fine. I think I assumed that rules are saved on textarea blur but they seem to be saved on window close. Either way, apologies for the noise and thanks again for sharing your work!

Just for clarification, textarea is saved on every edit and as you type.

Perhaps in case 1) the History API is used instead of a full page reload and that is not intercepted?

It is exactly as you say. History API / navigation isn't blocked at the moment. I took my time to solve this right away / thus later reply. At first I thought I'd just use "history" API to solve this, but as it's global, and doesn't have knowledge on which tab this navigation is happening, btw more about it at:
https://stackoverflow.com/questions/12865236/chrome-extension-history-api
https://stackoverflow.com/questions/51809258/get-tab-based-history-of-urls-in-chrome-extension-api
I decided to add "tabs" permission which works nicely to solve this.

Please, see the merge request (#53) to try this out. I have followed youtube example you provided to test it out, and it works as expected now.
As this change will be having a new "tabs" permission added, I shall release it as a new major version, 6.0 to be expected.

bard commented

Brilliant, thank you!

I installed the block-history-navigation and it appears to work as intended.

(Side note: I had to add "lib": ["dom", "es2021"] to tsconfig.json to get it to build.)

penge commented

Glad to hear!

Regarding that build, have you used:

$ npm run build

as at https://github.com/penge/block-site/actions/runs/5310575537/jobs/9612728265?pr=53 ?

bard commented

No, I used pnpm run build.