BozoWithTheBanjo
BozoWithTheBanjo
Aarktype
Created by DiamondDragon on 1/18/2025 in #questions
exact length "string = 2"
import { type } from 'arktype';

const x = type({
stateCode: '1 < string.alpha < 3',
});

const out = x({ stateCode: 'Error' });

if (out instanceof type.errors) {
console.error(out.summary);
}
// error is: stateCode must be exactly length 2 (was 5)
import { type } from 'arktype';

const x = type({
stateCode: '1 < string.alpha < 3',
});

const out = x({ stateCode: 'Error' });

if (out instanceof type.errors) {
console.error(out.summary);
}
// error is: stateCode must be exactly length 2 (was 5)
maybe something like this I think using = is assigning default value there
10 replies
Aarktype
Created by Sebaestschjin on 1/16/2025 in #questions
Recursive types and d.ts files
No description
8 replies
PD🧩 Plasmo Developers
Created by The Coding Sloth on 9/9/2023 in #👟framework
declarativeNetRequest
Thank you, I appriciate it!
15 replies
PD🧩 Plasmo Developers
Created by The Coding Sloth on 9/9/2023 in #👟framework
declarativeNetRequest
No description
15 replies
PD🧩 Plasmo Developers
Created by The Coding Sloth on 9/9/2023 in #👟framework
declarativeNetRequest
Do you maybe have an example how to do that?
15 replies
PD🧩 Plasmo Developers
Created by The Coding Sloth on 9/9/2023 in #👟framework
declarativeNetRequest
Hey, thank you for answering!
15 replies
PD🧩 Plasmo Developers
Created by The Coding Sloth on 9/9/2023 in #👟framework
declarativeNetRequest
Hey @The Coding Sloth Did you manage to get this to work? I have a similar case. How can I use the declarativeNetRequest to generate dynamic rules that work on both chrome and Firefox? I want to redirect network calls to my local server JS script when I am prototyping, but when I am not, I want to use a static link to my website, I will have a toggle button to determine which URL to redirect to.
async function setRedirectRule(newRedirectUrl: string) {
let newRedirectRule: chrome.declarativeNetRequest.Rule = {
id: RULE_ID,
priority: 1,
action: {
type: chrome.declarativeNetRequest.RuleActionType.REDIRECT,
redirect: { url: newRedirectUrl }
},
condition: {
urlFilter: "*://*/*",

resourceTypes: [chrome.declarativeNetRequest.ResourceType.MAIN_FRAME]
}
}

try {
chrome.declarativeNetRequest.updateDynamicRules({
removeRuleIds: [RULE_ID],
addRules: [newRedirectRule]
})
const currentRules = await chrome.declarativeNetRequest.getDynamicRules()
console.log("Redirect rule updated")
console.log("Current rules:", currentRules)
} catch (error) {
console.error("Error updating redirect rule:", error)
}
}
async function setRedirectRule(newRedirectUrl: string) {
let newRedirectRule: chrome.declarativeNetRequest.Rule = {
id: RULE_ID,
priority: 1,
action: {
type: chrome.declarativeNetRequest.RuleActionType.REDIRECT,
redirect: { url: newRedirectUrl }
},
condition: {
urlFilter: "*://*/*",

resourceTypes: [chrome.declarativeNetRequest.ResourceType.MAIN_FRAME]
}
}

try {
chrome.declarativeNetRequest.updateDynamicRules({
removeRuleIds: [RULE_ID],
addRules: [newRedirectRule]
})
const currentRules = await chrome.declarativeNetRequest.getDynamicRules()
console.log("Redirect rule updated")
console.log("Current rules:", currentRules)
} catch (error) {
console.error("Error updating redirect rule:", error)
}
}
If I put this into the background.ts it works for chrome, every time I open a new tab it just redirects to google. But it doesn't work for firefox. This is in my package.json:
"manifest": {
"host_permissions": [
"https://*/*"
],
"permissions": [
"tabs",
"declarativeNetRequest"
]
}
"manifest": {
"host_permissions": [
"https://*/*"
],
"permissions": [
"tabs",
"declarativeNetRequest"
]
}
15 replies