[英]How I can write the JavaScript code for Chrome extension that scroll down till end (I want to get all Facebook friends list)
I'm working on a Chrome extension and I have to read all my friends on Facebook without API. I have used window.scrollTo(0, document.body.scrollHeight);我正在开发 Chrome 扩展程序,我必须阅读 Facebook 上的所有朋友,而无需 API。我使用了 window.scrollTo(0, document.body.scrollHeight); in while loop with sleep function in Javascript but sleep pause all the javascript execution and Facebook data not load well.
在 Javascript 中睡眠 function 的 while 循环中,但睡眠暂停所有 javascript 执行和 Facebook 数据加载不正确。
friend list link https://web.facebook.com/profile-id/friends_all好友列表链接https://web.facebook.com/profile-id/friends_all
You can implement it this way- scroll, wait for the more content to load, compare scroll heights, and repeat if more content was loaded.您可以这样实现它——滚动,等待更多内容加载,比较滚动高度,如果加载更多内容则重复。 Here's the implementation with async/await and setTimeout sleep duration:
这是带有 async/await 和 setTimeout 睡眠持续时间的实现:
(async (sleepDuration = 2000) => {
let previousHeight;
let newHeight = document.body.scrollHeight;
do {
previousHeight = newHeight;
window.scrollTo(0, previousHeight);
await new Promise(resolve => setTimeout(resolve, sleepDuration));
newHeight = document.body.scrollHeight;
} while (previousHeight !== newHeight);
})();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.