Nike Login Chrome Extension - google-chrome-extension

I know there are other questions on the site like this but I am trying to log into nike using a chrome extension (the other questions are about selenium). I have all the proxies and everything but when I try and log in it doesn't work.
I ran the code I was using in the console and it worked but when I put it into a content script it gave me this "Processing your request. If this page doesn't refresh automatically, resubmit your request." I am using this code
setTimeout(function () {
if (document.getElementById("username")) {
replaceValue(document.getElementById("username"), emails[0])
setTimeout(function () {
document.getElementsByClassName("css-18y7846 btn-primary-dark btn-md")[0].click()
setTimeout(function () {
replaceValue(document.getElementById("password"), password[0])
}, 2000)
}, 10000)
}
}, 3000)

Related

Can you write a Chrome extension that runs nothing unless the devtools panel is open? [duplicate]

I have a new browser extension I'm developing, which means that to make it publicly available on the Chrome Web Store, I must use manifest v3. My extension is a DevTools extension, which means that to communicate with the content script, I have to use a background service worker to proxy the messages. Unfortunately, the docs on DevTools extensions haven't been updated for manifest v3, and the technique they suggest for messaging between the content script and the DevTools panel via the background script won't work if the background worker is terminated.
I've seen some answers here and Chromium project issue report comments suggest that the only available workaround is to reset the connection every five minutes. That seems hacky and unreliable. Is there a better mechanism for this, something more event based than an arbitrary timer?
We can make the connection hub out of the devtools_page itself. This hidden page runs inside devtools for the current tab, it doesn't unload while devtools is open, and it has full access to all of chrome API same as the background script.
manifest.json:
"devtools_page": "devtools.html",
"content_scripts": [{
"matches": ["<all_urls>"],
"js": ["content.js"],
"run_at": "document_start"
}]
devtools.html:
<script src="devtools.js"></script>
devtools.js:
let portDev, portTab;
const tabId = chrome.devtools.inspectedWindow.tabId;
const onDevMessage = msg => portTab.postMessage(msg);
const onTabMessage = msg => portDev.postMessage(msg);
chrome.runtime.onConnect.addListener(port => {
if (+port.name !== tabId) return;
portDev = port;
portDev.onMessage.addListener(onDevMessage);
portTab = chrome.tabs.connect(tabId, {name: 'dev'});
portTab.onMessage.addListener(onTabMessage);
});
// chrome.devtools.panels.create...
panel.js:
const port = chrome.runtime.connect({
name: `${chrome.devtools.inspectedWindow.tabId}`,
});
port.onMessage.addListener(msg => {
// This prints in devtools-on-devtools: https://stackoverflow.com/q/12291138
// To print in tab's console see `chrome.devtools.inspectedWindow.eval`
console.log(msg);
});
self.onclick = () => port.postMessage('foo');
content.js:
let portDev;
const onMessage = msg => {
console.log(msg);
portDev.postMessage('bar');
};
const onDisconnect = () => {
portDev = null;
};
chrome.runtime.onConnect.addListener(port => {
if (port.name !== 'dev') return;
portDev = port;
portDev.onMessage.addListener(onMessage);
portDev.onDisconnect.addListener(onDisconnect);
});
P.S. Regarding the 5-minute timer reset trick, if you still need the background script to be persistent, in this case it is reasonably reliable because the tab is guaranteed to be open while devtools for this tab is open.

"Scroll to Text" not working in Extension

I've built a Chrome Extension (pop-up) and one of the primary functions is opening different web pages when the user clicks on a link. Sometimes I want to focus on specific text on the new page so I'm trying to use the "scroll to text fragment" feature through my extension.
Unfortunately, when the page loads, this feature (scroll to text) fails. I have tested the exact same link manually and it works fine, but when I inject this link into the browser through my extension, nothing happens except the page loading as normal.
Here are a few more details that might help:
The problem I'm having is using Chrome.tabs.update() which is triggered by a user clicking a link in my popup
We are using manifest v2 not v3
The exact command from the popup javascript is (not tab id as it defaults to current tab):
chrome.tabs.update({ url: "http://example.com/#:~:text=example", })
In the manifest, we do not have the "tabs" permission.
Is there a special permission needed to use this feature in my extension? Is there something I need to do in my extension code to make this work as expected? I'm at a loss for next steps.
This is the exact feature I'm referring to: https://chromestatus.com/feature/4733392803332096
And here's an example of the feature in action:
https://chromestatus.com/feature/4733392803332096#:~:text=Motivation-,Navigating%20to%20a%20URL,-today%20will%20load
Any help would be greatly appreciated. Thank you.
There's no special permission so apparently it's a bug in Chrome: crbug.com/1241508
A simple workaround is to use chrome.tabs.create and close the original tab, but it flickers in the tab strip and loses the tab's back/forward history, sessionStorage, and so on.
function navigate(url) {
chrome.tabs.query({active: true, currentWindow: true}, ([tab]) => {
chrome.tabs.remove(tab.id);
chrome.tabs.create({ url, index: tab.index });
});
}
Another workaround is to set the hash part of the URL in the content script, but it requires host permissions for the navigated site in manifest.json like *://example.com/
async function navigate(url) {
if (await setUrlInContentScript(url)) {
return true;
}
const [base, hash] = url.split('#');
await onTabReceivedUrl(await new Promise(resolve => {
chrome.tabs.update({ url: base }, resolve);
}));
return setUrlInContentScript('#' + hash, 'hash');
function setUrlInContentScript(url, part = 'href') {
return new Promise(resolve => {
chrome.tabs.executeScript({
code: `location.${part}=${JSON.stringify(url)}`,
runAt: 'document_start',
}, () => resolve(!chrome.runtime.lastError));
});
}
function onTabReceivedUrl(tab) {
return new Promise(resolve => {
chrome.tabs.onUpdated.addListener(function onUpdated(tabId, info) {
if (tabId === tab.id && info.url) {
chrome.tabs.onUpdated.removeListener(onUpdated);
resolve();
}
});
});
}
}
In my case I discovered, that one of the characters ~ was encoded. You need the real characters to get Scroll to Text working.

Seeking on chrome audio player not working

I am trying to read a music from my backend on chrome / firefox/a ionic projet.
I cant click the timeline to chose a time I want to go to when I'm listening on google chrome or ionic music player. The music just restart from 00:00 when I do so . I tried doing a request from postman and it could read the music correctly and set the time I wanted when I clicked the timeline , same on firefox (its working correctly). However it does not work on chrome, as I said the music just restart when you click the timeline. Here is my backend route :
EDIT1 : my only hint is when I use howler.js as my player, if I pass the HTML5= true its not gonna work and if I dont put it its working, even if its open on chrome... (https://www.npmjs.com/package/howler) or maybe a header is missing ?
getMusic(req, res) {
try {
var trackID = new ObjectID(req.params.trackID);
} catch (err) {
return res.status(400).json({ message: "Invalid trackID in URL parameter. Must be a single String of 12 bytes or a string of 24 hex characters" });
}
res.set('content-type', 'audio/mpeg');
res.set('accept-ranges', 'bytes');
let bucket = new mongodb.GridFSBucket(db, {
bucketName: 'tracks'
});
let downloadStream = bucket.openDownloadStream(trackID);
downloadStream.on('data', (chunk) => {
res.write(chunk);
});
downloadStream.on('error', () => {
res.sendStatus(404);
});
downloadStream.on('end', () => {
res.end();
});
},
The "Content-length" header was missing on this code and after trying it with a dummy it works. I just need to find how to get the music length now, so I close this post.
example res.set('content-length', '5000000');

Can you "visit" a chrome-extension when testing with Cypress?

I'm trying to test my chrome-extension using cypress.io
I can successfully load my extension by adding this to plugins/index.js:
module.exports = (on, config) => {
on('before:browser:launch', (browser = {}, args) => {
if (browser.name === 'chrome') {
args.push('--load-extension=../bananatabs/build')
return args
}
})
}
I can open my extension's index.html on the cypress browser by navigating to
chrome-extension://ewoifjflksdjfioewjfoiwe/index.html
But when I try to "visit" it in a test, like this:
context('visit bananatabs', () => {
beforeEach(() => {
cy.visit('chrome-extension://inbalflcnihklpnmnnbdcinlfgnmplfl/index.html')
})
it('does nothing', () => {
assert(true);
});
});
it doesn't work. page reads:
Sorry, we could not load:
chrome-extension://inbalflcnihklpnmnnbdcinlfgnmplfl/index.html
In the docs all the examples use http or https protocols, not chrome-extension.
UPDATE
I can see the test page is http://localhost:54493/__/#/tests/integration/visit.spec.js and it contains an iframe with the page I'm testing, which uses chrome-extension:// protocol. I'm not sure that would ever work.
Can this be done?
Not Currently, but I've opened an issue for just that.
Cypress puts an arbitrary restriction for http/https, and could easily add support for browser specific protocols such as chrome://, resource://, and chrome-extension://
Feel free to throw a :+1: on it!

How to close a native web browser popup in Jasmine JS?

How to close a native web browser popup in Jasmine JS?
I can't succeed to close this dialog and it keep showing up in all the running.
Please your help!
The code:
describe('LiveSite Portal - Client perform a call', function() {
it('LiveSite - Home Page', function() {
liveSiteHome();
});
it('LiveSite Portal - Client perform a call', function() {
browser.getAllWindowHandles().then(function (handles) {
browser.switchTo().window(handles[handles.length - 1]);
var alertDialog = browser.switchTo().alert().thenCatch(function (e) {
if (e.code !== 27) { throw e; }
})
.then(function (alert) {
if (alert) {
expect(alertDialog.getText()).toEqual("External Protocol Request");
return alert.dismiss()
}
element(by.css("span.hide-sm.ng-binding")).click();
browser.sleep(3000);
});
//close the native popup
browser.switchTo().window(handles[0]);
browser.sleep(5000);
});
});
});
The actual result:
First of all, you cannot handle this kind of popup with protractor/selenium - it is not a javascript popup and you cannot switch to it or control. Your best bet is to avoid opening the popup in the first place by tweaking browser's desired capabilities, preferences.
I don't have a solution for google-chrome yet, but for Firefox you would need to set the following preferences by defining a custom Firefox Profile (see How To):
network.protocol-handler.expose-all -> false
network.protocol-handler.expose.callto -> false
This way you are letting Firefox know not to handle the external protocol link and do nothing.

Resources