WORLDBOOK

Worldbooks | WebMCP | Search | Submit WebMCP

facebook WebMCP

Browser tool configuration for facebook

URL Pattern: ^https?://(www\.)?facebook\.com(/.*)?$
Allowed Extra Domains: example.com, facebook.com

Tools (7)

facebook_events()

Browse Facebook event categories

Parameters

limit number - Number of categories

JavaScript Handler

(params) => {
  const args = Object.assign({"limit": 15}, params || {});
  let data = null;
  let __wbContextUrl = globalThis.location?.href || '';
  let __wbContextDocument = globalThis.document || null;
    const __wbDefault = (value, fallback) => (value === undefined || value === null || value === '' ? fallback : value);
    const __wbJoin = (value, separator) => Array.isArray(value) ? value.join(separator) : (value ?? '');
    const __wbGet = (value, path) => {
      if (!path) return value;
      return String(path).split('.').reduce((acc, part) => (acc == null ? undefined : acc[part]), value);
    };
    const __wbBaseUrl = () => (__wbContextUrl || globalThis.location?.href || 'https://example.com/');
    const __wbResolve = (target, base) => {
      if (target == null) return '';
      const text = String(target);
      try {
        return /^https?:/i.test(text) ? text : new URL(text, base || __wbBaseUrl()).toString();
      } catch (_error) {
        return text;
      }
    };
    const __wbFetch = async (target, options) => {
      const url = __wbResolve(target, __wbBaseUrl());
      const resp = await globalThis.fetch(url, Object.assign({ credentials: 'include' }, options || {}));
      if (!resp.ok) {
        throw new Error(`HTTP ${resp.status} for ${url}`);
      }
      const text = await resp.text();
      try {
        return { url, text, data: JSON.parse(text) };
      } catch (_error) {
        return { url, text, data: text };
      }
    };
  return (async () => {
    {
      const __wbResp = await __wbFetch("https://www.facebook.com/events");
      __wbContextUrl = __wbResp.url;
      __wbContextDocument = new DOMParser().parseFromString(__wbResp.text, 'text/html');
      data = __wbContextDocument;
    }
    {
      const document = __wbContextDocument || globalThis.document;
      const location = new URL(__wbBaseUrl());
      const window = { document, location };
      const fetch = (target, options) => globalThis.fetch(__wbResolve(target, __wbBaseUrl()), Object.assign({ credentials: 'include' }, options || {}));
      data = await (((() => {
  const limit = (args.limit);
  // Try actual event items first
  const articles = document.querySelectorAll('[role="article"]');
  if (articles.length > 0) {
    return Array.from(articles).slice(0, limit).map((el, i) => ({
      index: i + 1,
      name: el.textContent.trim().replace(/\s+/g, ' ').substring(0, 120),
    }));
  }

  // List event categories from sidebar navigation
  const links = Array.from(document.querySelectorAll('[role="navigation"] a'))
    .filter(a => {
      const href = a.href || '';
      const text = a.textContent.trim();
      return href.includes('/events/') && text.length > 1 && text.length < 60 &&
        !href.includes('create');
    });

  return links.slice(0, limit).map((a, i) => ({
    index: i + 1,
    name: a.textContent.trim(),
  }));
})())());
    }
    return data;
  })();
}

facebook_feed()

Get your Facebook news feed

Parameters

limit number - Number of posts

JavaScript Handler

(params) => {
  const args = Object.assign({"limit": 10}, params || {});
  let data = null;
  let __wbContextUrl = globalThis.location?.href || '';
  let __wbContextDocument = globalThis.document || null;
    const __wbDefault = (value, fallback) => (value === undefined || value === null || value === '' ? fallback : value);
    const __wbJoin = (value, separator) => Array.isArray(value) ? value.join(separator) : (value ?? '');
    const __wbGet = (value, path) => {
      if (!path) return value;
      return String(path).split('.').reduce((acc, part) => (acc == null ? undefined : acc[part]), value);
    };
    const __wbBaseUrl = () => (__wbContextUrl || globalThis.location?.href || 'https://example.com/');
    const __wbResolve = (target, base) => {
      if (target == null) return '';
      const text = String(target);
      try {
        return /^https?:/i.test(text) ? text : new URL(text, base || __wbBaseUrl()).toString();
      } catch (_error) {
        return text;
      }
    };
    const __wbFetch = async (target, options) => {
      const url = __wbResolve(target, __wbBaseUrl());
      const resp = await globalThis.fetch(url, Object.assign({ credentials: 'include' }, options || {}));
      if (!resp.ok) {
        throw new Error(`HTTP ${resp.status} for ${url}`);
      }
      const text = await resp.text();
      try {
        return { url, text, data: JSON.parse(text) };
      } catch (_error) {
        return { url, text, data: text };
      }
    };
  return (async () => {
    {
      const __wbResp = await __wbFetch("https://www.facebook.com/");
      __wbContextUrl = __wbResp.url;
      __wbContextDocument = new DOMParser().parseFromString(__wbResp.text, 'text/html');
      data = __wbContextDocument;
    }
    {
      const document = __wbContextDocument || globalThis.document;
      const location = new URL(__wbBaseUrl());
      const window = { document, location };
      const fetch = (target, options) => globalThis.fetch(__wbResolve(target, __wbBaseUrl()), Object.assign({ credentials: 'include' }, options || {}));
      data = await (((() => {
  const limit = (args.limit);
  const posts = document.querySelectorAll('[role="article"]');
  return Array.from(posts)
    .filter(el => {
      const text = el.textContent.trim();
      // Filter out "People you may know" suggestions (both CN and EN)
      return text.length > 30 &&
        !text.startsWith('可能认识') &&
        !text.startsWith('People you may know') &&
        !text.startsWith('People You May Know');
    })
    .slice(0, limit)
    .map((el, i) => {
      // Author from header link
      const headerLink = el.querySelector('h2 a, h3 a, h4 a, strong a');
      const author = headerLink ? headerLink.textContent.trim() : '';

      // Post text: grab visible spans, filter noise
      const spans = Array.from(el.querySelectorAll('div[dir="auto"]'))
        .map(s => s.textContent.trim())
        .filter(t => t.length > 10 && t.length < 500);
      const content = spans.length > 0 ? spans[0] : '';

      // Engagement: find like/comment/share counts (CN + EN)
      const allText = el.textContent;
      const likesMatch = allText.match(/所有心情:([\d,.\s]*[\d万亿KMk]+)/) ||
                         allText.match(/All:\s*([\d,.KMk]+)/) ||
                         allText.match(/([\d,.KMk]+)\s*(?:likes?|reactions?)/i);
      const commentsMatch = allText.match(/([\d,.]+\s*[万亿]?)\s*条评论/) ||
                            allText.match(/([\d,.KMk]+)\s*comments?/i);
      const sharesMatch = allText.match(/([\d,.]+\s*[万亿]?)\s*次分享/) ||
                          allText.match(/([\d,.KMk]+)\s*shares?/i);

      return {
        index: i + 1,
        author: author.substring(0, 50),
        content: content.replace(/\n/g, ' ').substring(0, 120),
        likes: likesMatch ? likesMatch[1] : '-',
        comments: commentsMatch ? commentsMatch[1] : '-',
        shares: sharesMatch ? sharesMatch[1] : '-',
      };
    });
})())());
    }
    return data;
  })();
}

facebook_friends()

Get Facebook friend suggestions

Parameters

limit number - Number of friend suggestions

JavaScript Handler

(params) => {
  const args = Object.assign({"limit": 10}, params || {});
  let data = null;
  let __wbContextUrl = globalThis.location?.href || '';
  let __wbContextDocument = globalThis.document || null;
    const __wbDefault = (value, fallback) => (value === undefined || value === null || value === '' ? fallback : value);
    const __wbJoin = (value, separator) => Array.isArray(value) ? value.join(separator) : (value ?? '');
    const __wbGet = (value, path) => {
      if (!path) return value;
      return String(path).split('.').reduce((acc, part) => (acc == null ? undefined : acc[part]), value);
    };
    const __wbBaseUrl = () => (__wbContextUrl || globalThis.location?.href || 'https://example.com/');
    const __wbResolve = (target, base) => {
      if (target == null) return '';
      const text = String(target);
      try {
        return /^https?:/i.test(text) ? text : new URL(text, base || __wbBaseUrl()).toString();
      } catch (_error) {
        return text;
      }
    };
    const __wbFetch = async (target, options) => {
      const url = __wbResolve(target, __wbBaseUrl());
      const resp = await globalThis.fetch(url, Object.assign({ credentials: 'include' }, options || {}));
      if (!resp.ok) {
        throw new Error(`HTTP ${resp.status} for ${url}`);
      }
      const text = await resp.text();
      try {
        return { url, text, data: JSON.parse(text) };
      } catch (_error) {
        return { url, text, data: text };
      }
    };
  return (async () => {
    {
      const __wbResp = await __wbFetch("https://www.facebook.com/friends");
      __wbContextUrl = __wbResp.url;
      __wbContextDocument = new DOMParser().parseFromString(__wbResp.text, 'text/html');
      data = __wbContextDocument;
    }
    {
      const document = __wbContextDocument || globalThis.document;
      const location = new URL(__wbBaseUrl());
      const window = { document, location };
      const fetch = (target, options) => globalThis.fetch(__wbResolve(target, __wbBaseUrl()), Object.assign({ credentials: 'include' }, options || {}));
      data = await (((() => {
  const limit = (args.limit);
  const items = document.querySelectorAll('[role="listitem"]');
  return Array.from(items)
    .slice(0, limit)
    .map((el, i) => {
      const text = el.textContent.trim().replace(/\s+/g, ' ');
      // Extract mutual info if present (before name extraction to avoid pollution)
      const mutualMatch = text.match(/([\d,]+)\s*位.*(?:关注|共同|mutual)/);
      // Extract name: remove mutual info, action buttons, etc.
      let name = text
        .replace(/[\d,]+\s*位.*(?:关注了|共同好友|mutual friends?)/, '')
        .replace(/加好友.*/, '').replace(/Add [Ff]riend.*/, '')
        .replace(/移除$/, '').replace(/Remove$/, '')
        .trim();
      return {
        index: i + 1,
        name: name.substring(0, 50),
        mutual: mutualMatch ? mutualMatch[1] : '-',
      };
    })
    .filter(item => item.name.length > 0);
})())());
    }
    return data;
  })();
}

facebook_groups()

List your Facebook groups

Parameters

limit number - Number of groups

JavaScript Handler

(params) => {
  const args = Object.assign({"limit": 20}, params || {});
  let data = null;
  let __wbContextUrl = globalThis.location?.href || '';
  let __wbContextDocument = globalThis.document || null;
    const __wbDefault = (value, fallback) => (value === undefined || value === null || value === '' ? fallback : value);
    const __wbJoin = (value, separator) => Array.isArray(value) ? value.join(separator) : (value ?? '');
    const __wbGet = (value, path) => {
      if (!path) return value;
      return String(path).split('.').reduce((acc, part) => (acc == null ? undefined : acc[part]), value);
    };
    const __wbBaseUrl = () => (__wbContextUrl || globalThis.location?.href || 'https://example.com/');
    const __wbResolve = (target, base) => {
      if (target == null) return '';
      const text = String(target);
      try {
        return /^https?:/i.test(text) ? text : new URL(text, base || __wbBaseUrl()).toString();
      } catch (_error) {
        return text;
      }
    };
    const __wbFetch = async (target, options) => {
      const url = __wbResolve(target, __wbBaseUrl());
      const resp = await globalThis.fetch(url, Object.assign({ credentials: 'include' }, options || {}));
      if (!resp.ok) {
        throw new Error(`HTTP ${resp.status} for ${url}`);
      }
      const text = await resp.text();
      try {
        return { url, text, data: JSON.parse(text) };
      } catch (_error) {
        return { url, text, data: text };
      }
    };
  return (async () => {
    {
      const __wbResp = await __wbFetch("https://www.facebook.com/groups/feed/");
      __wbContextUrl = __wbResp.url;
      __wbContextDocument = new DOMParser().parseFromString(__wbResp.text, 'text/html');
      data = __wbContextDocument;
    }
    {
      const document = __wbContextDocument || globalThis.document;
      const location = new URL(__wbBaseUrl());
      const window = { document, location };
      const fetch = (target, options) => globalThis.fetch(__wbResolve(target, __wbBaseUrl()), Object.assign({ credentials: 'include' }, options || {}));
      data = await (((() => {
  const limit = (args.limit);
  const links = Array.from(document.querySelectorAll('a'))
    .filter(a => {
      const href = a.href || '';
      return href.includes('/groups/') &&
        !href.includes('/feed') &&
        !href.includes('/discover') &&
        !href.includes('/joins') &&
        !href.includes('category=create') &&
        a.textContent.trim().length > 2;
    });

  // Deduplicate by href
  const seen = new Set();
  const groups = [];
  for (const a of links) {
    const href = a.href.split('?')[0];
    if (seen.has(href)) continue;
    seen.add(href);
    const raw = a.textContent.trim().replace(/\s+/g, ' ');
    // Split name from "上次发帖" info
    const parts = raw.split(/上次发帖|Last post/);
    groups.push({
      name: (parts[0] || '').trim().substring(0, 60),
      last_post: parts[1] ? parts[1].replace(/^[::]/, '').trim() : '-',
      url: href,
    });
  }
  return groups.slice(0, limit).map((g, i) => ({ index: i + 1, ...g }));
})())());
    }
    return data;
  })();
}

facebook_memories()

Get your Facebook memories (On This Day)

Parameters

limit number - Number of memories

JavaScript Handler

(params) => {
  const args = Object.assign({"limit": 10}, params || {});
  let data = null;
  let __wbContextUrl = globalThis.location?.href || '';
  let __wbContextDocument = globalThis.document || null;
    const __wbDefault = (value, fallback) => (value === undefined || value === null || value === '' ? fallback : value);
    const __wbJoin = (value, separator) => Array.isArray(value) ? value.join(separator) : (value ?? '');
    const __wbGet = (value, path) => {
      if (!path) return value;
      return String(path).split('.').reduce((acc, part) => (acc == null ? undefined : acc[part]), value);
    };
    const __wbBaseUrl = () => (__wbContextUrl || globalThis.location?.href || 'https://example.com/');
    const __wbResolve = (target, base) => {
      if (target == null) return '';
      const text = String(target);
      try {
        return /^https?:/i.test(text) ? text : new URL(text, base || __wbBaseUrl()).toString();
      } catch (_error) {
        return text;
      }
    };
    const __wbFetch = async (target, options) => {
      const url = __wbResolve(target, __wbBaseUrl());
      const resp = await globalThis.fetch(url, Object.assign({ credentials: 'include' }, options || {}));
      if (!resp.ok) {
        throw new Error(`HTTP ${resp.status} for ${url}`);
      }
      const text = await resp.text();
      try {
        return { url, text, data: JSON.parse(text) };
      } catch (_error) {
        return { url, text, data: text };
      }
    };
  return (async () => {
    {
      const __wbResp = await __wbFetch("https://www.facebook.com/onthisday");
      __wbContextUrl = __wbResp.url;
      __wbContextDocument = new DOMParser().parseFromString(__wbResp.text, 'text/html');
      data = __wbContextDocument;
    }
    {
      const document = __wbContextDocument || globalThis.document;
      const location = new URL(__wbBaseUrl());
      const window = { document, location };
      const fetch = (target, options) => globalThis.fetch(__wbResolve(target, __wbBaseUrl()), Object.assign({ credentials: 'include' }, options || {}));
      data = await (((() => {
  const limit = (args.limit);
  const articles = document.querySelectorAll('[role="article"]');
  return Array.from(articles)
    .slice(0, limit)
    .map((el, i) => {
      const headerLink = el.querySelector('h2 a, h3 a, h4 a, strong a');
      const spans = Array.from(el.querySelectorAll('div[dir="auto"]'))
        .map(s => s.textContent.trim())
        .filter(t => t.length > 5 && t.length < 500);
      const timeEl = el.querySelector('a[href*="/posts/"] span, a[href*="story_fbid"] span');
      return {
        index: i + 1,
        source: headerLink ? headerLink.textContent.trim().substring(0, 50) : '-',
        content: (spans[0] || '').replace(/\n/g, ' ').substring(0, 150),
        time: timeEl ? timeEl.textContent.trim() : '-',
      };
    })
    .filter(item => item.content.length > 0 || item.source !== '-');
})())());
    }
    return data;
  })();
}

facebook_notifications()

Get recent Facebook notifications

Parameters

limit number - Number of notifications

JavaScript Handler

(params) => {
  const args = Object.assign({"limit": 15}, params || {});
  let data = null;
  let __wbContextUrl = globalThis.location?.href || '';
  let __wbContextDocument = globalThis.document || null;
    const __wbDefault = (value, fallback) => (value === undefined || value === null || value === '' ? fallback : value);
    const __wbJoin = (value, separator) => Array.isArray(value) ? value.join(separator) : (value ?? '');
    const __wbGet = (value, path) => {
      if (!path) return value;
      return String(path).split('.').reduce((acc, part) => (acc == null ? undefined : acc[part]), value);
    };
    const __wbBaseUrl = () => (__wbContextUrl || globalThis.location?.href || 'https://example.com/');
    const __wbResolve = (target, base) => {
      if (target == null) return '';
      const text = String(target);
      try {
        return /^https?:/i.test(text) ? text : new URL(text, base || __wbBaseUrl()).toString();
      } catch (_error) {
        return text;
      }
    };
    const __wbFetch = async (target, options) => {
      const url = __wbResolve(target, __wbBaseUrl());
      const resp = await globalThis.fetch(url, Object.assign({ credentials: 'include' }, options || {}));
      if (!resp.ok) {
        throw new Error(`HTTP ${resp.status} for ${url}`);
      }
      const text = await resp.text();
      try {
        return { url, text, data: JSON.parse(text) };
      } catch (_error) {
        return { url, text, data: text };
      }
    };
  return (async () => {
    {
      const __wbResp = await __wbFetch("https://www.facebook.com/notifications");
      __wbContextUrl = __wbResp.url;
      __wbContextDocument = new DOMParser().parseFromString(__wbResp.text, 'text/html');
      data = __wbContextDocument;
    }
    {
      const document = __wbContextDocument || globalThis.document;
      const location = new URL(__wbBaseUrl());
      const window = { document, location };
      const fetch = (target, options) => globalThis.fetch(__wbResolve(target, __wbBaseUrl()), Object.assign({ credentials: 'include' }, options || {}));
      data = await (((() => {
  const limit = (args.limit);
  const items = document.querySelectorAll('[role="listitem"]');
  return Array.from(items)
    .filter(el => el.querySelectorAll('a').length > 0)
    .slice(0, limit)
    .map((el, i) => {
      const raw = el.textContent.trim().replace(/\s+/g, ' ');
      // Remove leading "未读" and trailing "标记为已读"
      const cleaned = raw.replace(/^未读/, '').replace(/标记为已读$/, '').replace(/^Unread/, '').replace(/Mark as read$/, '').trim();
      // Try to extract time (last segment like "11小时", "5天", "1周")
      const timeMatch = cleaned.match(/(\d+\s*(?:分钟|小时|天|周|个月|minutes?|hours?|days?|weeks?|months?))\s*$/);
      const time = timeMatch ? timeMatch[1] : '';
      const text = timeMatch ? cleaned.slice(0, -timeMatch[0].length).trim() : cleaned;
      return {
        index: i + 1,
        text: text.substring(0, 150),
        time: time || '-',
      };
    });
})())());
    }
    return data;
  })();
}

facebook_profile()

Get Facebook user/page profile info

Parameters

username string required - Facebook username or page name

JavaScript Handler

(params) => {
  const args = Object.assign({}, params || {});
  let data = null;
  let __wbContextUrl = globalThis.location?.href || '';
  let __wbContextDocument = globalThis.document || null;
    const __wbDefault = (value, fallback) => (value === undefined || value === null || value === '' ? fallback : value);
    const __wbJoin = (value, separator) => Array.isArray(value) ? value.join(separator) : (value ?? '');
    const __wbGet = (value, path) => {
      if (!path) return value;
      return String(path).split('.').reduce((acc, part) => (acc == null ? undefined : acc[part]), value);
    };
    const __wbBaseUrl = () => (__wbContextUrl || globalThis.location?.href || 'https://example.com/');
    const __wbResolve = (target, base) => {
      if (target == null) return '';
      const text = String(target);
      try {
        return /^https?:/i.test(text) ? text : new URL(text, base || __wbBaseUrl()).toString();
      } catch (_error) {
        return text;
      }
    };
    const __wbFetch = async (target, options) => {
      const url = __wbResolve(target, __wbBaseUrl());
      const resp = await globalThis.fetch(url, Object.assign({ credentials: 'include' }, options || {}));
      if (!resp.ok) {
        throw new Error(`HTTP ${resp.status} for ${url}`);
      }
      const text = await resp.text();
      try {
        return { url, text, data: JSON.parse(text) };
      } catch (_error) {
        return { url, text, data: text };
      }
    };
  return (async () => {
    {
      const __wbResp = await __wbFetch(`https://www.facebook.com/${args.username}`);
      __wbContextUrl = __wbResp.url;
      __wbContextDocument = new DOMParser().parseFromString(__wbResp.text, 'text/html');
      data = __wbContextDocument;
    }
    {
      const document = __wbContextDocument || globalThis.document;
      const location = new URL(__wbBaseUrl());
      const window = { document, location };
      const fetch = (target, options) => globalThis.fetch(__wbResolve(target, __wbBaseUrl()), Object.assign({ credentials: 'include' }, options || {}));
      data = await (((() => {
  const h1 = document.querySelector('h1');
  let name = h1 ? h1.textContent.trim() : '';

  // Find friends/followers links
  const links = Array.from(document.querySelectorAll('a'));
  const friendsLink = links.find(a => a.href && a.href.includes('/friends'));
  const followersLink = links.find(a => a.href && a.href.includes('/followers'));

  return [{
    name: name,
    username: ((args.username)),
    friends: friendsLink ? friendsLink.textContent.trim() : '-',
    followers: followersLink ? followersLink.textContent.trim() : '-',
    url: window.location.href,
  }];
})())());
    }
    return data;
  })();
}

🔌 Chrome MCP Server Extension

Use these tools with Claude, ChatGPT, and other AI assistants.

Get Extension →

How to Use WebMCP

WebMCP tools are designed for browser extensions or automation frameworks. The browser extension matches the current URL against the pattern and executes the JavaScript handler when the tool is invoked.

API Endpoint:

GET /api/webmcp/match?url=https://www.facebook.com/...