Automating Facebook Ad Posting
Automating Facebook Ad Posting (Copilot Skill)
Builds a self-contained Copilot skill directory that generates, lints, and publishes ad copy to Facebook groups/Pages fully autonomously, while minimizing ban risk through strict volume/timing guardrails and human-mimicking interaction patterns.
Deploy the skill tree to %USERPROFILE%\.copilot\skills\fb-ads-publisher\:
fb-ads-publisher/
├── SKILL.md # the skill definition Copilot reads
├── config/
│ ├── targets.yaml # groups/pages, quotas, cooldowns
│ └── voice.md # writing style + banned phrases
├── scripts/
│ ├── setup.ps1 # installs playwright + deps
│ ├── doctor.py # verifies CDP access to the Store app
│ ├── attach.py # launches app with --remote-debugging-port
│ ├── guard.py # decides WHICH targets are postable NOW
│ ├── lint_copy.py # rejects spammy/duplicate copy (exit 1 = fail)
│ ├── post_fb.py # does the actual human-like posting
│ └── status.py # quota/cooldown report
└── state/ # runtime: fb_state.json, posted.jsonl, shots/
Then tell Copilot: "publish the facebook campaign using fb-ads-publisher".
It runs the full loop with zero human steps beyond the one-time login.
Progress:
- Step 0: Run
doctor.py— confirm CDP reachability to the Store app (or fall back to--engine web) - Step 1: Run
guard.py --now— get the list of currently-eligible targets + quota - Step 2: Draft one unique copy variant per eligible target, following
voice.md - Step 3: Run
lint_copy.pyper draft — rewrite until zero errors - Step 4: Run
post_fb.py— publishes sequentially with randomized inter-post delays - Step 5: Report a Markdown table (target | status | excerpt | screenshot) + quota summary
Never parallelize Step 4. Never bypass guard.py's eligibility list. Never
reuse identical copy across targets.
Core technical insight
The Facebook Store app is a WebView2 PWA, not a native app — same DOM as the web, which
means the entire anti-ban logic and Playwright selector strategy from a browser-based
bot transfers directly. The only different part is the transport: launch the app with
WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS=--remote-debugging-port=9222, then
playwright.chromium.connect_over_cdp("http://127.0.0.1:9222") to attach to the live
window instead of spawning a headless browser.
- Volume: 3–5 posts/day total, 1 per group per 48h. New accounts: 1/day for 7 days, 2/day until day 14, then full cap.
- Timing windows: only 08:00–12:00 and 17:00–22:00 local time, with 3–11 min jitter.
- Day-skipping: ~12% chance of skipping a day entirely, 30% on weekends.
- Copy uniqueness: hash every published text (SHA-256 of normalized lowercase), reject exact repeats. Vary length (90–320 chars), structure, and CTA every time.
- No link in first line. Put the link after 2 lines, or as a first comment for strict groups.
- Human browsing before posting: scroll the feed 45–120s and like 1–3 posts before opening the composer.
- Single session, single browser window — never run two posting jobs concurrently.
- Checkpoint detection: if the page shows a Facebook checkpoint/verification screen, abort the entire campaign immediately and surface it at the top of the report.
- Human-like typing: char-by-char with randomized delay (45–160ms, longer after punctuation), occasional backspace-retype to simulate typos.
Example 1: Input: "publish the facebook campaign" Output:
| target | status | excerpt | screenshot |
|---------------|--------|-------------------------------------------|-----------------------|
| grp-fr-vpn | OK | ça fait un moment que je teste des conf... | shots/...-grp.png |
| page-perso | FAIL | marre de payer pour du vent, celle-là... | shots/...-page.png |
1/2 posts succeeded. Remaining quota today: 1. Next window: 17:00–22:00.
Failure cause (page-perso): composer selector not found — DOM may have changed.
Example 2:
Input: guard.py returns {"eligible": [], "reason": "quiet_hours"}
Output: Nothing to publish — outside posting window (quiet_hours). No action taken.
- Use a dedicated Facebook account, never the user's primary account.
- First run should target a low-stakes destination (own Page) before hitting groups.
- Keep three alternate composer/publish-button selectors (fr/en variants) since Facebook's DOM churns frequently — this is the most common single point of failure.
- Log every attempt (success and failure) to
state/posted.jsonlfor dedupe and cooldown math — never skip logging on exception paths. - If a target fails twice, mark it
paused: trueintargets.yamland move on; don't retry indefinitely.
- Don't bypass or hand-edit
guard.py's eligibility output to "just post anyway" — this is precisely what triggers bans. - Don't run
post_fb.pyconcurrently with another instance —attach.pykills the app process before relaunching, which will clobber a parallel run. - Don't post identical or near-identical copy across targets — hash-check first.
- Don't expose the CDP debug port (9222) on any network interface beyond localhost.
- Don't treat a composer-not-found error as transient after 3 consecutive failures — that signals a DOM change requiring selector updates, not a retry loop.
- Don't assume native Android/iOS app automation is possible this way — this approach is specific to the Windows Store app's WebView2/Chromium architecture.