-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset-privacy-policy.js
More file actions
122 lines (113 loc) · 4.21 KB
/
Copy pathset-privacy-policy.js
File metadata and controls
122 lines (113 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* play-console set-privacy-policy
*
* Set the Privacy Policy URL for an app in Google Play Console.
* This field lives under App content → Privacy policy and is NOT
* accessible via the Google Play Developer API.
*
* Prerequisites:
* - Chrome logged into play.google.com/console
* - The extension daemon running (opencli doctor)
*/
import { cli, Strategy } from '@jackwener/opencli/registry';
import { appUrl, waitForPlayConsole, clickSave } from './_shared.js';
cli({
site: 'play-console',
name: 'set-privacy-policy',
description: 'Set the Privacy Policy URL for an app (App content → Privacy policy)',
domain: 'play.google.com',
strategy: Strategy.UI,
args: [
{
name: 'dev_id',
required: true,
positional: true,
help: 'Developer account ID (numeric, from Play Console URL)',
},
{
name: 'app_id',
required: true,
positional: true,
help: 'App ID (numeric, from Play Console URL)',
},
{
name: 'url',
required: true,
help: 'Privacy policy URL (must start with https://)',
},
{
name: 'acc_idx',
type: 'int',
default: 0,
help: 'Google account index in Play Console (default: 0)',
},
],
columns: ['success', 'url', 'message'],
func: async (page, kwargs) => {
const { dev_id, app_id, url, acc_idx } = kwargs;
if (!String(url).startsWith('http')) {
throw new Error(`Privacy policy URL must start with https://: ${url}`);
}
const targetUrl = appUrl(String(dev_id), String(app_id), 'app-content/privacy-policy', Number(acc_idx));
await page.goto(targetUrl, { waitUntil: 'networkidle' });
await waitForPlayConsole(page);
// Play Console privacy policy page has a single URL input field
const filled = await page.evaluate((privacyUrl) => {
// Try various selector patterns used in Play Console
const inputSelectors = [
'input[name="privacyPolicyUrl"]',
'input[formcontrolname="privacyPolicyUrl"]',
'input[placeholder*="privacy"]',
'input[placeholder*="Privacy"]',
'input[type="url"]',
'.privacy-policy-url input',
'gpc-text-input input',
];
for (const sel of inputSelectors) {
const input = document.querySelector(sel);
if (input) {
// Trigger Angular's change detection by dispatching native events
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
window.HTMLInputElement.prototype, 'value'
).set;
nativeInputValueSetter.call(input, privacyUrl);
input.dispatchEvent(new Event('input', { bubbles: true }));
input.dispatchEvent(new Event('change', { bubbles: true }));
return { found: true, selector: sel };
}
}
return { found: false };
}, String(url));
if (!filled.found) {
// Fallback: use Playwright's fill with visible text inputs
const inputs = await page.$$('input:visible, input[type="url"], input[type="text"]');
if (inputs.length === 0) {
throw new Error(
'Could not find privacy policy URL input on the page. ' +
'Make sure Chrome is logged into Play Console and the page loaded correctly. ' +
`Page URL: ${page.url()}`
);
}
// Most likely the first/only input on this page is the URL field
await inputs[0].triple_click?.() ?? inputs[0].click();
await inputs[0].fill(String(url));
}
await page.waitForTimeout(500);
await clickSave(page);
// Verify the save by checking for success toast or that the input now shows the URL
const saved = await page.evaluate((expectedUrl) => {
const toast = document.querySelector('.success-snack, .mat-snack-bar-container, gpc-snackbar');
if (toast && toast.textContent?.includes('save')) return true;
// Check if input now contains the URL
const inputs = document.querySelectorAll('input');
return Array.from(inputs).some(i => i.value === expectedUrl);
}, String(url));
return [{
success: saved,
url: String(url),
message: saved
? 'Privacy policy URL saved successfully'
: 'Save button clicked — verify in Play Console that the change was applied',
}];
},
});