Skip to content

Instantly share code, notes, and snippets.

@codebling
Created March 31, 2020 00:12
Show Gist options
  • 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>');
@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