Skip to content

Instantly share code, notes, and snippets.

@codebling
Created March 31, 2020 00:12
Show Gist options
  • Star 25 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codebling/3b7bfdbfbabf7bc17d8566b92854b4c3 to your computer and use it in GitHub Desktop.
Save codebling/3b7bfdbfbabf7bc17d8566b92854b4c3 to your computer and use it in GitHub Desktop.
let bookmarkList = Array.from(document.querySelectorAll('.widget>.vbox'))
.map(e => e.shadowRoot)
.map(e => e && e.querySelector('.device-page-list'))
.find(e => e);
let bookmarks = Array.from(bookmarkList.querySelectorAll('.vbox'))
.map(e => `<a href="${e.querySelector('x-link').innerHTML}">${e.querySelector('.device-page-title').innerHTML}</a>`);
copy('<html><body>' + bookmarks.join('\n') + '</body></html>');
@bashor
Copy link

bashor commented May 5, 2020

Version for Chrome 81.*:

var tabsNodes = document.querySelectorAll('.browser>.list.pages>.row')
var tabsAsText = Array.from(tabsNodes).map((t) => t.querySelector(".name").innerText + "\n" + t.querySelector(".url").innerText + "\n")
copy(tabsAsText.join("\n"))

@codebling
Copy link
Author

@bashor thanks!!

@7UR7L3
Copy link

7UR7L3 commented Jul 2, 2020

@bashor's version for Chrome 81.* still works on Chrome 83.* but note that the .url divs are capped to 100 chars.

If you open the dev console -> sources -> page/top/inspect/inspect.js and ctrl+f for 100 you should be able to comment out these lines (select and ctrl+/)

//   if (text.length > 100) {
//     text = text.substring(0, 100) + '\u2026';
//   }

and save those updates (ctrl+s).

Either do this shortly after a page reload (you have plenty of time) or just unplug and replug the phone and the list will update with the full urls.

Edit: see Ben J's comment on this answer here https://android.stackexchange.com/a/193858/326682 .

@codebling
Copy link
Author

@7UR7L3 awesome thanks for the info! I'm honestly hoping I'll never have to go through the same process again..Trying to avoid opening so many tabs on my phone now :)

@Hibrix-net
Copy link

@bashor's version for Chrome 81.* still works on Chrome 83.* but note that the .url divs are capped to 100 chars.

If you open the dev console -> sources -> page/top/inspect/inspect.js and ctrl+f for 100 you should be able to comment out these lines (select and ctrl+/)

//   if (text.length > 100) {
//     text = text.substring(0, 100) + '\u2026';
//   }

and save those updates (ctrl+s).

Either do this shortly after a page reload (you have plenty of time) or just unplug and replug the phone and the list will update with the full urls.

Edit: see Ben J's comment on this answer here https://android.stackexchange.com/a/193858/326682 .

That's brilliant, many thanks!

@moisesbaddini
Copy link

Chrome 81+ changed devices page.
You should visit chrome://inspect/#devices on a new tab, then F12 to open console on that page.
After that, continue using the commands above!

@codebling
Copy link
Author

Should I move this to a full git repo?

@Hibrix-net
Copy link

Should I move this to a full git repo?

Yes for me.

Thanks,

@SpiicyPuddiing
Copy link

I tried it last year and it worked.

I tried it again today and its not working.
This seems to be pretty old. I am not sure if it still works.
When I try to save the "100" string part as comment, it gives me an error "Changes to this file were not saved to file system"

And even without this when I run the code from here on the console, it says, "Paused on promise rejection."
"TypeError: Cannot read property 'querySelectorAll' of undefined"

@codebling
Copy link
Author

@SpiicyPuddiing agreed, it is pretty old, and I have not tried it in some time. What line is your error on?

@SpiicyPuddiing
Copy link

Oops. I totally forgot about this and now I am back to needing the solution again xD
So sorry about the delay.

I cant explain all the things so heres a video showing my issue xD
https://www.youtube.com/watch?v=BTqln9aw8L4

@codebling
Copy link
Author

@SpiicyPuddiing the video you linked appears to have nothing to do with the code snippet above?

@SpiicyPuddiing
Copy link

Really? I thought the snippet assumes the links are not capped at 100 characters.
I am stuck on this step.

@bashor's version for Chrome 81.* still works on Chrome 83.* but note that the .url divs are capped to 100 chars.

If you open the dev console -> sources -> page/top/inspect/inspect.js and ctrl+f for 100 you should be able to comment out these lines (select and ctrl+/)

//   if (text.length > 100) {
//     text = text.substring(0, 100) + '\u2026';
//   }

and save those updates (ctrl+s).

Either do this shortly after a page reload (you have plenty of time) or just unplug and replug the phone and the list will update with the full urls.

Edit: see Ben J's comment on this answer here https://android.stackexchange.com/a/193858/326682 .

@codebling
Copy link
Author

@SpiicyPuddiing oh sorry, I see you're referring to @7UR7L3's comment to circumvent the length limitation, right? Sorry for the confusion!

I see it's blocking you from saving the changes - I'm not sure what can be done about that. I have not tried this tweak myself.

I've since switched to Firefox for other reasons (bookmark management is certainly not one of them) and have been using the sync. Let me know if I can help in any way or if you find a solution

@7UR7L3
Copy link

7UR7L3 commented Mar 28, 2021

Really? I thought the snippet assumes the links are not capped at 100 characters.
I am stuck on this step.

@bashor's version for Chrome 81.* still works on Chrome 83.* but note that the .url divs are capped to 100 chars.
If you open the dev console -> sources -> page/top/inspect/inspect.js and ctrl+f for 100 you should be able to comment out these lines (select and ctrl+/)

//   if (text.length > 100) {
//     text = text.substring(0, 100) + '\u2026';
//   }

and save those updates (ctrl+s).
Either do this shortly after a page reload (you have plenty of time) or just unplug and replug the phone and the list will update with the full urls.
Edit: see Ben J's comment on this answer here https://android.stackexchange.com/a/193858/326682 .

@SpiicyPuddiing These steps still work for me (on Chrome 89.0.4389.90). The important part, after saving the changes to inspect.js (and after the warning displays on the inspect.js tab), is to unplug and replug your phone to get the chrome://inspect/#devices page to reload the tab list, re-running the edited script (don't refresh the page or it will revert the changes to inspect.js; also, after unplugging, wait for the tab list to clear before replugging your phone). It takes maybe 5-10 seconds for me for the list refresh to happen, and for me to then be able to use bashor's script to copy the tab list to the clipboard.

If that doesn't work, as a last resort, you can try to make the following changes to inspect.js (click to expand)
make all of these changes simultaneously, only saving the file once after performing all of the following edits to the script:

comment out lines 533-535
//   if (text.length > 100) {
//     text = text.substring(0, 100) + '\u2026';
//   }

comment out lines 256-258
//   if (alreadyDisplayed(deviceList, devices)) {
//     return;
//   }

comment out lines 316-318
//     if (alreadyDisplayed(deviceSection, device)) {
//       continue;
//     }

comment out lines 330-332
//     Array.prototype.forEach.call(
//         browserList.querySelectorAll('.browser'),
//         removeObsolete.bind(null, newBrowserIds));

modify line 428 by
changing        if (!alreadyDisplayed(browserSection, browser)) {
into            if (true) {

The tab list should reload with the full urls after a few seconds, as the populateTargets method is triggered frequently.

The Changes to this file were not saved to file system warning is expected. I'd guess it shows that warning for people using dev tools for developing their own source code, where there's probably some sort of file system integration to be able to edit code directly in Chrome. We're editing Chrome's own script, so reloading the page will pull the script again and overwrite our changes (not sure if there's a way to use a session version of a file in Chrome, though that would be nice). However, our edit to the loaded script still takes effect for the duration of the session, and works because the page calls the function several times (before and after modification).

@Katalogo
Copy link

Katalogo commented Jun 1, 2021

Version for Chrome 81.*:

var tabsNodes = document.querySelectorAll('.browser>.list.pages>.row')
var tabsAsText = Array.from(tabsNodes).map((t) => t.querySelector(".name").innerText + "\n" + t.querySelector(".url").innerText + "\n")
copy(tabsAsText.join("\n"))

In total there are 905 tabs opened in my android chrome app. Is there any way to copy selective URLs.
I want to copy all the URLs of the website "mangajar.com" from my android chrome app.

@codebling
Copy link
Author

@7UR7L3 awesome, thanks for the detailed instructions!

@Pbiswas262f why not just import them all, search for mangajar.com and delete the others?
If you really need to do it in Javascript for some obscure reason and also don't know how to do it in Javascript, then you can try adding .filter(t => t.querySelector(".url").innerText.includes("mangajar.com")) between Array.from(tabsNodes) and .map. I have not tested this and if there are issues with this than I suggest you stick to importing them all and copying the ones you want.

@SpiicyPuddiing
Copy link

Really? I thought the snippet assumes the links are not capped at 100 characters.
I am stuck on this step.

@bashor's version for Chrome 81.* still works on Chrome 83.* but note that the .url divs are capped to 100 chars.
If you open the dev console -> sources -> page/top/inspect/inspect.js and ctrl+f for 100 you should be able to comment out these lines (select and ctrl+/)

//   if (text.length > 100) {
//     text = text.substring(0, 100) + '\u2026';
//   }

and save those updates (ctrl+s).
Either do this shortly after a page reload (you have plenty of time) or just unplug and replug the phone and the list will update with the full urls.
Edit: see Ben J's comment on this answer here https://android.stackexchange.com/a/193858/326682 .

@SpiicyPuddiing These steps still work for me (on Chrome 89.0.4389.90). The important part, after saving the changes to inspect.js (and after the warning displays on the inspect.js tab), is to unplug and replug your phone to get the chrome://inspect/#devices page to reload the tab list, re-running the edited script (don't refresh the page or it will revert the changes to inspect.js; also, after unplugging, wait for the tab list to clear before replugging your phone). It takes maybe 5-10 seconds for me for the list refresh to happen, and for me to then be able to use bashor's script to copy the tab list to the clipboard.

If that doesn't work, as a last resort, you can try to make the following changes to inspect.js (click to expand)
The Changes to this file were not saved to file system warning is expected. I'd guess it shows that warning for people using dev tools for developing their own source code, where there's probably some sort of file system integration to be able to edit code directly in Chrome. We're editing Chrome's own script, so reloading the page will pull the script again and overwrite our changes (not sure if there's a way to use a session version of a file in Chrome, though that would be nice). However, our edit to the loaded script still takes effect for the duration of the session, and works because the page calls the function several times (before and after modification).

Ope, didnt know you replied. I will try it soon. Thank you for taking the time to write :3

@liumuyv
Copy link

liumuyv commented Jun 3, 2022

Version for Chrome 81.*:

var tabsNodes = document.querySelectorAll('.browser>.list.pages>.row')
var tabsAsText = Array.from(tabsNodes).map((t) => t.querySelector(".name").innerText + "\n" + t.querySelector(".url").innerText + "\n")
copy(tabsAsText.join("\n"))

still work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment